Browse Source

Fix for issue #119

Stephen Ficklin 7 years ago
parent
commit
12aea71e60

+ 7 - 1
tripal/includes/TripalFields/TripalField.inc

@@ -284,7 +284,13 @@ class TripalField {
     $bundle_name = $this->instance['bundle'];
     $field_name = $this->field['field_name'];
 
-    $data[$bundle_name][$field_name] = array(
+    // Fields should be associated with the bundle's term identifier
+    // (i.e. [vocab]__[accession].
+    $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
+    $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
+    $table = $term->vocab->vocabulary . '__' . $term->accession;
+
+    $data[$table][$field_name] = array(
       'title' => $this->instance['label'],
       'help' => $this->instance['description'],
       'field' => array(

+ 13 - 7
tripal/tripal.views.inc

@@ -89,14 +89,20 @@ function tripal_views_data_tripal_entity(&$data) {
   // Iterate through the bundles.
   while ($bundle = $bundles->fetchObject()) {
 
+    // This isn't really the table name, but because our bundle table
+    // names are unique on every Tripal site we must ust a more generic
+    // name.  Because we're using our own query class this should be fine.
+    $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
+    $table = $term->vocab->vocabulary . '__' . $term->accession;
+
     // Each bundle gets it's own "table".
-    $data[$bundle->name]['table']['group'] = t($bundle->label);
-    $data[$bundle->name]['table']['base'] = array(
+    $data[$table]['table']['group'] = t($bundle->label);
+    $data[$table]['table']['base'] = array(
       'query class' => 'tripal_views_query',
       'title' => t($bundle->label),
       'help' => t('Tripal ' . $bundle->label . ' pages'),
     );
-    $data[$bundle->name]['entity_id'] = array(
+    $data[$table]['entity_id'] = array(
       'title' => t('Entity ID'),
       'help' => t('The unique entity ID for this content type.'),
       'field' => array(
@@ -109,7 +115,7 @@ function tripal_views_data_tripal_entity(&$data) {
         'handler' => 'views_handler_sort',
       ),
     );
-    $data[$bundle->name]['link'] = array(
+    $data[$table]['link'] = array(
       'title' => t('Link'),
       'help' => t('Provide a simple link to the content.'),
       'field' => array(
@@ -122,7 +128,7 @@ function tripal_views_data_tripal_entity(&$data) {
         'handler' => 'views_handler_sort',
       ),
     );
-    $data[$bundle->name]['edit_link'] = array(
+    $data[$table]['edit_link'] = array(
       'title' => t('Edit Link'),
       'help' => t('Provide a simple link to edit the content.'),
       'field' => array(
@@ -135,7 +141,7 @@ function tripal_views_data_tripal_entity(&$data) {
         'handler' => 'views_handler_sort',
       ),
     );
-    $data[$bundle->name]['delete_link'] = array(
+    $data[$table]['delete_link'] = array(
       'title' => t('Delete Link'),
       'help' => t('Provide a simple link to delete the content.'),
       'field' => array(
@@ -148,7 +154,7 @@ function tripal_views_data_tripal_entity(&$data) {
         'handler' => 'views_handler_sort',
       ),
     );
-    $data[$bundle->name]['status'] = array(
+    $data[$table]['status'] = array(
       'title' => t('Published'),
       'help' => t('Whether or not the content is published.'),
       'field' => array(

+ 10 - 2
tripal/tripal_views_query.inc

@@ -39,6 +39,7 @@ class tripal_views_query extends views_plugin_query {
    *
    */
   public function init($base_table = 'tripal_entity', $base_field = 'id', $options) {
+
     parent::init($base_table, $base_field, $options);
 
     $this->fields = array();
@@ -47,9 +48,16 @@ class tripal_views_query extends views_plugin_query {
     // Creqte the TripalFieldQuery object.
     $this->query = new TripalFieldQuery();
 
-    // Make suer we only query on the entities for this bundle type.
+    // Convert the $base_table into the bundle table.  Because every
+    // tripal site will have different bundle tables we have to do the
+    // conversion for cross-site compatibility.
+    list($vocabulary, $accession) = explode('__', $base_table);
+    $term = tripal_load_term_entity(array('vocabulary' => $vocabulary, 'accession' => $accession));
+    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
+
+    // Make sure we only query on the entities for this bundle type.
     $this->query->entityCondition('entity_type', 'TripalEntity');
-    $this->query->entityCondition('bundle', $base_table);
+    $this->query->entityCondition('bundle', $bundle->name);
   }
   /**
    *

+ 4 - 1
tripal_chado/includes/tripal_chado.fields.inc

@@ -2159,7 +2159,10 @@ function tripal_chado_field_views_data_alter(&$result, $field, $module) {
   // so we need to set some handlers.
   if ($field['field_name'] == 'data__image') {
     foreach ($result as $key => $fields) {
-      if (preg_match('/^bio_data/', $key)) {
+      // It's not clear how to identify our bundle types, but they do have
+      // a double underscore in their name to separate the vocabulary from
+      // the accession, so we'll use that to find them.
+      if (preg_match('/__/', $key)) {
         $result[$key]['data__image']['field']['handler'] = 'tripal_views_handler_field_image';
       }
     }