Browse Source

Restructured the tripal_bundle and tripal_entity tables

Stephen Ficklin 9 years ago
parent
commit
61af51fcbd

+ 4 - 4
tripal_chado/api/tripal_chado.api.inc

@@ -24,11 +24,11 @@
  *       FIELD_CARDINALITY_UNLIMITED for unlimited number of values.
  * @param $entity_type_name
  *   The entity type name.
- * @param $bundle_id
+ * @param $bundle_name
  *   The bundle name.
  *
  */
-function tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_id) {
+function tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name) {
 
   $field = field_info_field($field_name);
 
@@ -36,7 +36,7 @@ function tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $b
   // there is nothing left to do.
   if ($field and array_key_exists('bundles', $field) and
       array_key_exists($entity_type_name, $field['bundles']) and
-      in_array($bundle_id, $field['bundles'][$entity_type_name])) {
+      in_array($bundle_name, $field['bundles'][$entity_type_name])) {
     return;
   }
 
@@ -75,7 +75,7 @@ function tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $b
     'entity_type' => $entity_type_name,
     'required' => $field_info['is_required'],
     'settings' => $field_info['field_settings'],
-    'bundle' => $bundle_id,
+    'bundle' => $bundle_name,
   );
   field_create_instance($field_instance);
 }

+ 10 - 18
tripal_chado/includes/fields/kvproperty.inc

@@ -43,19 +43,11 @@ function tripal_chado_kvproperty_widget(&$widget, $form, $form_state, $field, $i
   $entity = $form['#entity'];
   $field_name = $field['field_name'];
 
-  // Get the bundle and the table it maps to.
-  $bundle = tripal_load_bundle_entity($entity->bundle);
-  $chado_table = tripal_get_bundle_variable('chado_table', $bundle->id);
-  $chado_column = tripal_get_bundle_variable('chado_column', $bundle->id);
-
-  // Get the chado record.
-  $chado_entity = db_select('chado_entity' ,'ce')
-    ->fields('ce')
-    ->condition('ce.entity_id', $entity->id)
-    ->execute()
-    ->fetchObject();
-  $schema = chado_get_schema($chado_table);
-  $record = chado_select_record($chado_table, array('*'), array($schema['primary key'][0] => $chado_entity->record_id));
+  // Get the record and table mapping info.
+  $chado_table = $entity->chado_table;
+  $chado_column = $entity->chado_column;
+  $chado_record = $entity->chado_record;
+
   $matches = array();
   preg_match('/(.*?)__(\d+)/', $field_name, $matches);
   // If the field name is not properly formatted then we can't tell what
@@ -79,8 +71,8 @@ function tripal_chado_kvproperty_widget(&$widget, $form, $form_state, $field, $i
   if (array_key_exists($delta, $items)) {
     $propval = $items[$delta][$table_name . '__value'];
   }
-  if (count($record) > 0) {
-    $fk_value = $record[0]->$rfkey_field;
+  if ($chado_record) {
+    $fk_value = $chado_record->$rfkey_field;
   }
 
 
@@ -136,9 +128,9 @@ function tripal_chado_kvproperty_widget_validate($element, &$form_state) {
   $entity = $element['#entity'];
   $matches = array();
 
-  $bundle = tripal_load_bundle_entity($entity->bundle);
-  $chado_table = tripal_get_bundle_variable('chado_table', $bundle->id);
-  $chado_column = tripal_get_bundle_variable('chado_column', $bundle->id);
+  // Get the record and table mapping info.
+  $chado_table = $entity->chado_table;
+  $chado_column = $entity->chado_column;
 
   // Get the table name and cvterm_id for this field.
   preg_match('/(.*?)__(\d+)/', $field_name, $matches);

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

@@ -44,7 +44,7 @@ function tripal_chado_kvproperty_adder_widget(&$widget, $form, $form_state,
     '#type' => 'textfield',
     '#description' => t("Please enter the type of property that you want to
         add.  As you type, suggestions will be provided."),
-    '#autocomplete_path' => "admin/tripal/vocab/cvterm/auto_name/",
+    '#autocomplete_path' => "admin/tripal/vocab/cvterm/auto_name//",
   );
   $widget['kvproperty_adder_link'] = array(
     '#type' => 'item',

+ 71 - 59
tripal_chado/includes/tripal_chado.entity.inc

@@ -1,5 +1,31 @@
 <?php
 
+
+/**
+ * Implements hook_entity_create().
+ *
+ * This hook is called when brand new entities are created, but
+ * they are not loaded so the hook_entity_load() is not yet called.
+ */
+function tripal_chado_entity_create(&$entity, $type) {
+  if ($type == 'TripalEntity') {
+
+    // Set some defaults on vars needed by this module.
+    $entity->chado_table = NULL;
+    $entity->chado_column = NULL;
+    $entity->chado_record = NULL;
+    $entity->chado_record_id = NULL;
+
+    // Add in the Chado table information for this entity type.
+    $bundle = tripal_load_bundle_entity($entity->bundle);
+    $chado_table = tripal_get_bundle_variable('chado_table', $bundle->id);
+    $chado_column = tripal_get_bundle_variable('chado_column', $bundle->id);
+    if ($chado_table) {
+      $entity->chado_table = $chado_table;
+      $entity->chado_column = $chado_column;
+    }
+  }
+}
 /**
  * Implements hook_entity_presave().
  */
@@ -20,21 +46,56 @@ function tripal_chado_entity_postsave($entity, $type) {
 }
 
 /**
- *
  * Implements hook_entity_load().
  */
 function tripal_chado_entity_load($entities, $type) {
- // TODO: we should add the cvterm record and the Chado record to the
- // entity.  This way the kvproperty field (or any other's we add in the
- // future do not need to load all of that information.  This can create
- // multiple loading of the same records all over the place.
+  if ($type == 'TripalEntity') {
+    foreach ($entities as $entity) {
+
+      // We want to add in the record ID to the entity.
+      if (property_exists($entity, 'id')) {
+
+        // Set some defaults on vars needed by this module.
+        $entity->chado_table = NULL;
+        $entity->chado_column = NULL;
+        $entity->chado_record = NULL;
+        $entity->chado_record_id = NULL;
+
+        // Add in the Chado table information for this entity type.
+        $bundle = tripal_load_bundle_entity($entity->bundle);
+        $chado_table = tripal_get_bundle_variable('chado_table', $bundle->id);
+        $chado_column = tripal_get_bundle_variable('chado_column', $bundle->id);
+        if ($chado_table) {
+          $entity->chado_table = $chado_table;
+          $entity->chado_column = $chado_column;
+        }
+
+        $chado_entity = db_select('chado_entity' ,'ce')
+          ->fields('ce')
+          ->condition('ce.entity_id', $entity->id)
+          ->execute()
+          ->fetchObject();
+        $schema = chado_get_schema($chado_table);
+        $record = chado_generate_var($chado_table, array($schema['primary key'][0] => $chado_entity->record_id));
+        $entity->chado_record = $record;
+        $entity->chado_record_id = $chado_entity->record_id;
+      }
+    }
+  }
+}
+
+/**
+ * Implements hook_field_attach_form().
+ */
+function tripal_chado_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
+
 }
 
 /**
  *
  * Implements hook_entity_insert().
  */
-function tripal_entities_entity_insert($entity, $type) {
+function tripal_chado_entity_insert($entity, $type) {
 
 }
 
@@ -52,10 +113,10 @@ function tripal_chado_entity_update($entity, $type) {
  */
 function tripal_chaddo_entity_delete($entity, $type) {
   $record = db_select('chado_entity', 'ce')
-   ->fields('ce', array('chado_entity_id', 'data_table', 'record_id'))
-   ->condition('entity_id', $entity->id)
-   ->execute()
-   ->fetchObject();
+    ->fields('ce', array('chado_entity_id', 'data_table', 'record_id'))
+    ->condition('entity_id', $entity->id)
+    ->execute()
+    ->fetchObject();
 
   if ($record && property_exists($record, 'chado_entity_id')) {
     // Delete the corresponding record in Chado
@@ -69,28 +130,6 @@ function tripal_chaddo_entity_delete($entity, $type) {
   }
 }
 
-/**
- * This theme function is meant to override the data_combo theme.
- *
- * @param $variables
- */
-function theme_tripal_chado_date_combo($variables) {
-  $element = $variables['element'];
-  $field = field_info_field($element['#field_name']);
-  $instance = field_info_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']);
-
-  // Group start/end items together in fieldset.
-  $fieldset = array(
-    '#title' => t($element['#title']) . ' ' . ($element['#delta'] > 0 ? intval($element['#delta'] + 1) : ''),
-    '#value' => '',
-    '#description' => !empty($element['#fieldset_description']) ? $element['#fieldset_description'] : '',
-    '#attributes' => array(),
-    '#children' => $element['#children'],
-    '#attributes' => array('class' => array('collapsible', 'collapsed')),
-  );
-  return theme('fieldset', array('element' => $fieldset));
-}
-
 
 /**
  * Determines whether the given user has access to a tripal data entity.
@@ -122,30 +161,3 @@ function tripal_chado_entity_access($op, $entity = NULL, $account = NULL) {
   }
   return FALSE;
 }
-
-/**
- * Menu callback to display an entity.
- *
- * As we load the entity for display, we're responsible for invoking a number
- * of hooks in their proper order.
- *
- * @see hook_entity_prepare_view()
- * @see hook_entity_view()
- * @see hook_entity_view_alter()
- */
-function tripal_chado_view_entity($entity, $view_mode = 'full') {
-  $content = '';
-  $controller = entity_get_controller($entity->type);
-  $content = $controller->view(array($entity->id => $entity));
-  drupal_set_title($entity->title);
-  return $content;
-}
-
-/**
- * Menu title callback for showing individual entities
- */
-function tripal_chado_entity_title($entity){
-  if ($entity) {
-    return $entity->title;
-  }
-}

+ 4 - 14
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -24,20 +24,10 @@ function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
   $term = reset($term);
 
   // Get the base table, type field and record_id from the entity.
-  $base_table = tripal_get_bundle_variable('chado_table', $bundle->id);
-  $type_field = tripal_get_bundle_variable('chado_column', $bundle->id);
-
-  // Look for an record in the chado_entity table for this entity.
-  $chado_entity = db_select('chado_entity', 'ct')
-    ->fields('ct')
-    ->condition('ct.entity_id', $entity->id)
-    ->execute()
-    ->fetchObject();
-
-  $record_id = NULL;
-  if ($chado_entity) {
-    $record_id  = $chado_entity->record_id;
-  }
+  $base_table = $entity->chado_table;
+  $type_field = $entity->chado_column;
+  $record     = $entity->chado_record;
+  $record_id  = $entity->chado_record_id;
 
   // Convert the fields into a key/value list of fields and their values.
   $field_vals = tripal_chado_field_storage_unnest_fields($fields, $entity_type, $entity);

+ 9 - 8
tripal_chado/includes/tripal_chado.term_storage.inc

@@ -22,24 +22,25 @@ function tripal_chado_vocab_storage_info() {
  *
  * @param $namespace
  *   The namespace of the vocabulary in which the term is found.
- * @param $term_id
+ * @param $accession
  *   The unique identifier (accession) for this term.
  *
  * @return
  *   An array with at least the following keys:
- *     id : The name unique ID of the term.
+ *     namespace : The namespace of the vocabulary.
+ *     accession : The name unique ID of the term.
  *     name : The name of the term.
  *     definition : The term's description.
  *   any other keys may be added as desired. Returns NULL if the term
  *   cannot be found.
  */
-function tripal_chado_vocab_get_term($namespace, $term_id) {
+function tripal_chado_vocab_get_term($namespace, $accession) {
   $match = array(
     'dbxref_id' => array(
       'db_id' => array(
         'name' => $namespace,
       ),
-      'accession' => $term_id
+      'accession' => $accession,
     ),
   );
   $cvterm = chado_generate_var('cvterm', $match);
@@ -48,7 +49,8 @@ function tripal_chado_vocab_get_term($namespace, $term_id) {
   }
   $cvterm = chado_expand_var($cvterm, 'field', 'cvterm.definition');
   return array(
-    'id' => $cvterm->dbxref_id->accession,
+    'namespace' => $cvterm->dbxref_id->db_id->name,
+    'accession' => $cvterm->dbxref_id->accession,
     'name' => $cvterm->name,
     'definition' => (isset($cvterm->definition)) ? $cvterm->definition : '',
     'cvterm' => $cvterm,
@@ -126,7 +128,6 @@ function tripal_chado_vocab_select_term_form_validate($form, &$form_state) {
     $term_name = NULL;
     $cv_id = NULL;
     $cvterm = NULL;
-    $term_id = NULL;
     if (array_key_exists('term_name', $form_state['values'])) {
       $term_name = $form_state['input']['term_name'];
     }
@@ -162,10 +163,10 @@ function tripal_chado_vocab_select_term_form_validate($form, &$form_state) {
       form_set_error('term_name', t('The term is not unique. A list of vocabularies
         that contain this term. Please select the most appropriate vocabulary.'));
     }
-    // If we have a unique term then set the namespace, term_id and name.
+    // If we have a unique term then set the namespace, accession and name.
     if (count($terms) == 1) {
       $form_state['storage']['namespace'] = $terms[0]->dbxref_id->db_id->name;
-      $form_state['storage']['term_id']   = $terms[0]->dbxref_id->accession;
+      $form_state['storage']['accession'] = $terms[0]->dbxref_id->accession;
       $form_state['storage']['term_name'] = $terms[0]->name;
     }
   }

+ 23 - 0
tripal_chado/theme/tripal_chado.theme.inc

@@ -0,0 +1,23 @@
+<?php
+
+/**
+ * This theme function is meant to override the data_combo theme.
+ *
+ * @param $variables
+ */
+function theme_tripal_chado_date_combo($variables) {
+  $element = $variables['element'];
+  $field = field_info_field($element['#field_name']);
+  $instance = field_info_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']);
+
+  // Group start/end items together in fieldset.
+  $fieldset = array(
+    '#title' => t($element['#title']) . ' ' . ($element['#delta'] > 0 ? intval($element['#delta'] + 1) : ''),
+    '#value' => '',
+    '#description' => !empty($element['#fieldset_description']) ? $element['#fieldset_description'] : '',
+    '#attributes' => array(),
+    '#children' => $element['#children'],
+    '#attributes' => array('class' => array('collapsible', 'collapsed')),
+  );
+  return theme('fieldset', array('element' => $fieldset));
+}

+ 4 - 3
tripal_chado/tripal_chado.module

@@ -1,6 +1,7 @@
 <?php
 
 require_once "api/tripal_chado.api.inc";
+require_once "includes/tripal_chado.entity.inc";
 require_once "includes/tripal_chado.term_storage.inc";
 require_once "includes/tripal_chado.field_storage.inc";
 
@@ -516,7 +517,7 @@ function tripal_chado_theme($existing, $type, $theme, $path) {
     ),
     'tripal_chado_date_combo' => array(
       'render element' => 'element',
-      'file' => 'includes/tripal_chado.entity.inc',
+      'file' => 'theme/tripal_chado.theme.inc',
     ),
   );
 }
@@ -526,7 +527,7 @@ function tripal_chado_theme($existing, $type, $theme, $path) {
  */
 function tripal_chado_add_bundle_fields($entity_type, $bundle, $term) {
 
-  $bundle_name = $bundle->bundle;
+  $bundle_name = $bundle->name;
 
   // This array will hold details that map the bundle to tables in Chado.
   $bundle_data = array();
@@ -539,7 +540,7 @@ function tripal_chado_add_bundle_fields($entity_type, $bundle, $term) {
       'db_id' => array(
         'name' => $vocab->namespace,
       ),
-      'accession' => $term->term_id
+      'accession' => $term->accession
     ),
   );
   $cvterm = chado_generate_var('cvterm', $match);

+ 54 - 16
tripal_entities/api/tripal_entities.api.inc

@@ -4,19 +4,19 @@
  *
  * @param $namespace
  *   The namespace for the vocabulary
- * @param $term_id
+ * @param $accession
  *   The ID (accession) of the term in the vocabulary.
  *
  * @return
  *   A TripalTerm entity object or NULL if not found.
  */
-function tripal_load_term_entity($namespace, $term_id) {
+function tripal_load_term_entity($namespace, $accession) {
   $query = db_select('tripal_term', 'tt');
   $query->join('tripal_vocab' ,'tv', 'tv.id = tt.vocab_id');
-  $query->fields('tt', array('id', 'term_id'))
+  $query->fields('tt', array('id', 'accession'))
     ->fields('tv', array('namespace'))
     ->condition('tv.namespace', $namespace)
-    ->condition('tt.term_id', $term_id);
+    ->condition('tt.accession', $accession);
   $term = $query->execute()->fetchObject();
 
   if ($term) {
@@ -60,7 +60,7 @@ function tripal_load_vocab_entity($namespace) {
 function tripal_load_bundle_entity($name) {
   $bundle = db_select('tripal_bundle', 'tb')
     ->fields('tb')
-    ->condition('tb.bundle', $name)
+    ->condition('tb.name', $name)
     ->execute()
     ->fetchObject();
 
@@ -75,7 +75,7 @@ function tripal_load_bundle_entity($name) {
  *
  * @param $namespace
  *   The abbreviated namespace for the vocabulary (e.g. RO, SO, PATO).
- * @param $term_id
+ * @param $accession
  *   The unique term ID in the vocabulary $namespace (i.e. an accession).
  * @param $term_name
  *   A human-readable name for this term.  This will became the name that
@@ -88,7 +88,7 @@ function tripal_load_bundle_entity($name) {
  * @return
  *  TRUE if the entity type (bundle) was succesfully created.  FALSE otherwise.
  */
-function tripal_create_bundle($namespace, $term_id, $term_name, &$error = '') {
+function tripal_create_bundle($namespace, $accession, $term_name, &$error = '') {
 
   // First create the TripalVocab if it doesn't already exist.
   $vocab = tripal_load_vocab_entity($namespace);
@@ -98,23 +98,24 @@ function tripal_create_bundle($namespace, $term_id, $term_name, &$error = '') {
   }
 
   // Next create the TripalTerm if it doesn't already exist.
-  $term = tripal_load_term_entity($namespace, $term_id);
+  $term = tripal_load_term_entity($namespace, $accession);
   if (!$term) {
-    $args = array('vocab_id' => $vocab->id, 'term_id' => $term_id, 'name' => $term_name);
+    $args = array('vocab_id' => $vocab->id, 'accession' => $accession, 'name' => $term_name);
     $term = entity_get_controller('TripalTerm')->create($args);
     $term = $term->save();
   }
 
   // If the bundle doesn't already exist, then add it.
-  $bundle_id = 'bio-data_' . $term->id;
+  $bundle_name = 'bio-data_' . $term->id;
   $einfo = entity_get_info('TripalEntity');
-  if (!in_array($bundle_id, array_keys($einfo['bundles']))) {
+  if (!in_array($bundle_name, array_keys($einfo['bundles']))) {
     // Insert the bundle.
     db_insert('tripal_bundle')
       ->fields(array(
         'label' => $term_name,
         'type' => 'TripalEntity',
-        'bundle' => $bundle_id,
+        'name' => $bundle_name,
+        'term_id' => $term->id,
       ))
       ->execute();
   }
@@ -127,7 +128,7 @@ function tripal_create_bundle($namespace, $term_id, $term_name, &$error = '') {
   variable_set('menu_rebuild_needed', TRUE);
 
   // Get the bundle object.
-  $bundle = tripal_load_bundle_entity($bundle_id);
+  $bundle = tripal_load_bundle_entity($bundle_name);
 
   // Allow modules to now add fields to the bundle
   module_invoke_all('add_bundle_fields', 'TripalEntity', $bundle, $term);
@@ -135,6 +136,18 @@ function tripal_create_bundle($namespace, $term_id, $term_name, &$error = '') {
   return TRUE;
 }
 
+/**
+ * Allows a module to make changes to an entity object after creation.
+ *
+ * This function is added by Tripal to allow datastore backends to add
+ * addition properties to the entity that they themselves will use later.
+ *
+ * @param $entity
+ * @param $entity_type
+ */
+function hook_entity_create(&$entity, $entity_type) {
+
+}
 /**
  * Allows a module to add fields to a bundle.
  *
@@ -319,7 +332,7 @@ function tripal_get_default_title_format($entity) {
 function tripal_get_tokens($entity) {
   $tokens = array();
 
-  $fields = field_info_instances('TripalEntity', $entity->bundle);
+  $fields = field_info_instances('TripalEntity', $entity->name);
   foreach ($fields as $f) {
 
     // Build the token from the field information.
@@ -402,9 +415,9 @@ function hook_vocab_storage_info() {
  * This hook allows the module that implements a vocabulary storage backend
  * to provide the form necessary to select a term that will then be used for
  * creating a new TripalEntity type.  Tripal will expect that a 'namespace' and
- * 'term_id' are in the $form_state['storage'] array. The 'namespace' and
+ * 'accession' are in the $form_state['storage'] array. The 'namespace' and
  * must be the abbreviated uppercase namespace for the vocabulary (e.g. 'RO',
- * 'SO', 'PATO', etc.).  The 'term_id' must be the unique term ID (or
+ * 'SO', 'PATO', etc.).  The 'accession' must be the unique term ID (or
  * accession) for the term in the vocabulary.
  *
  * @param $form
@@ -425,3 +438,28 @@ function hook_vocab_select_term_form(&$form, &$form_state) {
 function hook_vocab_select_term_form_validate($form, &$form_state) {
 
 }
+
+/**
+ * Retreives information about a term from the default term storage backend.
+ *
+ * This hook is called by the tripal_entity module to retrieve information
+ * about the term from the storage backend.  It must return an array with
+ * a set of keys.
+ *
+ * @param $namespace
+ *   The namespace of the vocabulary in which the term is found.
+ * @param $accession
+ *   The unique identifier (accession) for this term.
+ *
+ * @return
+ *   An array with at least the following keys:
+ *     namespace : The namespace of the vocabulary.
+ *     accession : The name unique ID of the term.
+ *     name : The name of the term.
+ *     definition : The term's description.
+ *   any other keys may be added as desired. Returns NULL if the term
+ *   cannot be found.
+ */
+function hook_vocab_get_term($namespace, $accession) {
+
+}

+ 6 - 6
tripal_entities/includes/TripalBundleUIController.inc

@@ -74,8 +74,8 @@ class TripalBundleUIController extends EntityDefaultUIController {
 function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType) {
 
   $entity_type = $form_state['build_info']['args'][0];
-  if (preg_match('/bio-data_(\d+)/', $entity_type->term_id, $matches)) {
-    $term = entity_load('TripalTerm', array('id' => $entity_type->term_id));
+  if (preg_match('/bio-data_(\d+)/', $entity_type->name, $matches)) {
+    $term = entity_load('TripalTerm', array('id' => $matches[1]));
     $term = reset($term);
     $vocab = entity_load('TripalVocab', array('id' => $term->vocab_id));
     $vocab = reset($vocab);
@@ -327,19 +327,19 @@ function tripal_entities_admin_add_type_form_validate($form, &$form_state) {
  */
 function tripal_entities_admin_add_type_form_submit($form, &$form_state) {
   $namespace = '';
-  $term_id = '';
+  $accession = '';
   if (array_key_exists('storage', $form_state)) {
     $storage = $form_state['storage'];
     $namespace = array_key_exists('namespace', $storage) ? $storage['namespace'] : '';
-    $term_id = array_key_exists('term_id', $storage) ? $storage['term_id'] : '';
+    $accession = array_key_exists('accession', $storage) ? $storage['accession'] : '';
     $term_name = array_key_exists('term_name', $storage) ? $storage['term_name'] : '';
 
     // Before we try to add this type, check to see if it already exists
     // as a bundle.
-    $term = tripal_load_term_entity($namespace, $term_id);
+    $term = tripal_load_term_entity($namespace, $accession);
     if (!$term) {
       $error = '';
-      $success = tripal_create_bundle($namespace, $term_id, $term_name, $error);
+      $success = tripal_create_bundle($namespace, $accession, $term_name, $error);
       if (!$success) {
         drupal_set_message($error, 'error');
         $form_state['redirect'] = "admin/structure/bio-data";

+ 15 - 11
tripal_entities/includes/TripalEntityController.inc

@@ -33,17 +33,20 @@ class TripalEntityController extends EntityAPIController {
     $values['created'] = time();
     $values['changed'] = time();
     $values['title'] = '';
+    $values['type'] = 'TripalEntity';
 
-    // The incoming values should have at a minimum the bundle_id;
-    $bundle = $values['bundle'];
-    $matches = array();
-    if (preg_match('/bio-data_(.*)/', $bundle, $matches)) {
-      $term_id = $matches[1];
-      $values['type'] = 'TripalEntity';
-      $values['term_id'] = $term_id;
+    // Call the parent constructor.
+    $entity = parent::create($values);
+
+    // Allow modules to make additions to the entity when it's created.
+    $modules = module_implements('entity_create');
+    foreach ($modules as $module) {
+      $function = $module . '_entity_create';
+      $function($entity, $values['type']);
     }
 
-    return parent::create($values);
+    return $entity;
+
   }
 
   /**
@@ -84,7 +87,7 @@ class TripalEntityController extends EntityAPIController {
     if (!$title) {
 
       // First get the format for the title based on the bundle of the entity.
-      $bundle_entity = tripal_bundle_load($entity->bundle);
+      $bundle_entity = tripal_load_bundle_entity($entity->bundle);
       $title = tripal_get_title_format($bundle_entity);
 
       // Determine which tokens were used in the format string
@@ -180,8 +183,9 @@ class TripalEntityController extends EntityAPIController {
     catch (Exception $e) {
       $transaction->rollback();
       watchdog_exception('tripal_core', $e);
-      drupal_set_message("Could not save the entity:" . $e->getMessage(), "error");
+      drupal_set_message("Could not save the entity: " . $e->getMessage(), "error");
       return FALSE;
     }
   }
-}
+}
+

+ 190 - 9
tripal_entities/includes/TripalEntityUIController.inc

@@ -30,8 +30,6 @@ class TripalEntityUIController extends EntityDefaultUIController {
     $items['bio-data/add'] = array(
       'title' => 'Add Tripal Content',
       'page callback' => 'tripal_entities_add_page',
-      'file' =>  'includes/tripal_entities.entity_form.inc',
-      'file path' => drupal_get_path('module', 'tripal_entities'),
       'access arguments' => array('administer tripal data'),
     );
 
@@ -52,8 +50,6 @@ class TripalEntityUIController extends EntityDefaultUIController {
           'page arguments' => array('tripal_entities_entity_form', 2),
           'access callback'  => 'tripal_entities_entity_access',
           'access arguments' => array('edit'),
-          'file' =>  'includes/tripal_entities.entity_form.inc',
-          'file path' => drupal_get_path('module', 'tripal_entities'),
         );
       }
     }
@@ -87,8 +83,6 @@ class TripalEntityUIController extends EntityDefaultUIController {
       'page arguments' => array('tripal_entities_entity_form', NULL, 1),
       'access callback' => 'tripal_entities_entity_access',
       'access arguments' => array('edit', 1),
-      'file' =>  'includes/tripal_entities.entity_form.inc',
-      'file path' => drupal_get_path('module', 'tripal_entities'),
       'type' => MENU_LOCAL_TASK,
       'weight' => -8,
     );
@@ -100,8 +94,6 @@ class TripalEntityUIController extends EntityDefaultUIController {
       'page arguments' => array('tripal_entities_entity_delete_form', 1),
       'access callback' => 'tripal_entities_entity_access',
       'access arguments' => array('edit', 1),
-      'file' =>  'includes/tripal_entities.entity_form.inc',
-      'file path' => drupal_get_path('module', 'tripal_entities'),
       'type' => MENU_CALLBACK,
       'weight' => 10,
     );
@@ -114,7 +106,7 @@ class TripalEntityUIController extends EntityDefaultUIController {
  * @param unknown $entity
  */
 function tripal_entity_manage_fields($entity) {
-  drupal_goto('admin/structure/bio-data/manage/' . $entity->bundle . '/fields');
+  drupal_goto('admin/structure/bio-data/manage/' . $entity->name . '/fields');
   return '';
 }
 
@@ -237,3 +229,192 @@ function tripal_entities_view_entity($entity, $view_mode = 'full') {
 
    return $form;
  }
+
+ /**
+  *
+  */
+ function tripal_entities_entity_form($form, &$form_state, $term_id = '', $entity = NULL) {
+
+   $bundle_name = 'bio-data_' . $term_id;
+
+   // Add a vertical tabs element
+   $form['entity_form_vtabs'] = array(
+     '#type' => 'vertical_tabs',
+     '#weight' => 999,
+   );
+
+   // If the entity doesn't exist then create one.
+   if (!$entity) {
+     $entity = entity_get_controller('TripalEntity')->create(array('bundle' => $bundle_name, 'term_id' => $term_id));
+     field_attach_form('TripalEntity', $entity, $form, $form_state);
+
+     $form['add_button'] = array(
+       '#type' => 'submit',
+       '#value' => t('Save'),
+       '#name' => 'add_data',
+       '#weight' => 1000
+     );
+   }
+   else {
+     field_attach_form('TripalEntity', $entity, $form, $form_state);
+     $form['update_button'] = array(
+       '#type' => 'submit',
+       '#value' => t('Update'),
+       '#name' => 'update_data',
+       '#weight' => 1000
+     );
+     $form['delete_button'] = array(
+       '#type' => 'submit',
+       '#value' => t('Delete'),
+       '#name' => 'delete_data',
+       '#weight' => 1001
+     );
+   }
+
+   // The entity object must be added to the $form_state in order for
+   // the Entity API to work. It must have a key of the entity name.
+   $form_state['TripalEntity'] = $entity;
+
+   $form['#prefix'] = "<div id='$bundle_name-entity-form'>";
+   $form['#suffix'] = "</div>";
+   return $form;
+
+ }
+ /**
+  * An Ajax callback for the tripal_entities_entity_form.
+  */
+ function tripal_entities_entity_form_ajax_callback($form, $form_state) {
+   // return the form so Drupal can update the content on the page
+   return $form;
+ }
+
+ /**
+  * Implements hook_validate() for the tripal_entities_entity_form.
+  */
+ function tripal_entities_entity_form_validate($form, &$form_state) {
+
+   if (array_key_exists('clicked_button', $form_state) and
+       $form_state['clicked_button']['#name'] =='add_data') {
+         $entity = $form_state['TripalEntity'];
+         field_attach_form_validate('TripalEntity', $entity, $form, $form_state);
+       }
+ }
+
+
+ /**
+  * Implements hook_submit() for the tripal_entities_entity_form.
+  */
+ function tripal_entities_entity_form_submit($form, &$form_state) {
+   $entity = $form_state['TripalEntity'];
+
+   if ($form_state['clicked_button']['#name'] =='cancel') {
+     $form_state['redirect'] = "bio-data/" . $entity->id;
+   }
+
+   if ($form_state['clicked_button']['#name'] =='update_data' or
+       $form_state['clicked_button']['#name'] =='add_data') {
+
+     $entityform = entity_ui_controller('TripalEntity')->entityFormSubmitBuildEntity($form, $form_state);
+     if ($entityform->save()) {
+       $form_state['redirect'] = "bio-data/" . $entity->id;
+     }
+     else {
+       drupal_set_message('Cannot save entity', 'error');
+     }
+   }
+   if ($form_state['clicked_button']['#name'] =='delete_data') {
+     $form_state['redirect'] = 'bio-data/' . $entity->id .'/delete';
+   }
+ }
+
+
+ /**
+  * Provides a list of TripalEntity types (bundles) for the user to add.
+  *
+  * This function is a callback in a menu item which is set in the
+  * TripalEntityUIController class.
+  */
+ function tripal_entities_add_page() {
+   $item = menu_get_item();
+
+   $content = system_admin_menu_block($item);
+
+   // Bypass the node/add listing if only one content type is available.
+   if (count($content) == 1) {
+     $item = array_shift($content);
+     drupal_goto($item['href']);
+   }
+   return theme('tripal_entities_add_list', array('content' => $content));
+
+ }
+
+ /**
+  * Returns HTML for a list of available node types for node creation.
+  *
+  * @param $variables
+  *   An associative array containing:
+  *   - content: An array of content types.
+  *
+  * @ingroup themeable
+  */
+ function theme_tripal_entities_add_list($variables) {
+   $content = $variables['content'];
+   $output = '';
+
+   if ($content) {
+     $output = '<dl class="node-type-list">';
+     foreach ($content as $item) {
+       $output .= '<dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>';
+       $output .= '<dd>' . filter_xss_admin($item['description']) . '</dd>';
+     }
+     $output .= '</dl>';
+   }
+   else {
+     $output = tripal_set_message(
+         t('This page is for adding Tripal content to your site. However, before you can add data you have to specify what types of data your site will support. For example, if you want to add genes to be displayed to users, you must first create a data type "gene".'),
+         TRIPAL_INFO,
+         array('return_html' => TRUE)
+     );
+     $output .= '<p>' . t('You have not created any biological data types yet. ' .
+         'Go to the <a href="@create-content">data type creation page</a> to ' .
+         'add a new biological data type.',
+         array('@create-content' => url('admin/structure/bio-data/add'))) . '</p>';
+   }
+   return $output;
+ }
+
+ /**
+  * Form callback: confirmation form for deleting a tripal_entity.
+  *
+  * @param $tripal_entity The
+  *          tripal_entity to delete
+  *
+  * @see confirm_form()
+  */
+ function tripal_entities_entity_delete_form($form, &$form_state, $entity) {
+   $form_state['entity'] = $entity;
+   $form['#submit'][] = 'tripal_entities_entity_delete_form_submit';
+
+   $form = confirm_form($form,
+       t('Click the delete button below to confirm deletion of the record titled: %title',
+           array('%title' => $entity->title)), 'admin/content/tripal_entity',
+       '<p>' .t('This action cannot be undone.') .'</p>', t('Delete'), t('Cancel'), 'confirm');
+
+   return $form;
+ }
+
+ /**
+  * Submit callback for tripal_entity_delete_form
+  */
+ function tripal_entities_entity_delete_form_submit($form, &$form_state) {
+   $entity = $form_state['entity'];
+
+   $entity_controller = new TripalEntityController($entity->type);
+   if ($entity_controller->delete($entity)) {
+     drupal_set_message(t('The record title "%name" has been deleted.', array('%name' => $entity->title)));
+     $form_state['redirect'] = 'admin/content/tripal_entitys';
+   }
+   else {
+     drupal_set_message(t('The tripal_entity %name was not deleted.', array('%name' => $entity->title)), "error");
+   }
+ }

+ 1 - 1
tripal_entities/includes/TripalTerm.inc

@@ -22,7 +22,7 @@ class TripalTerm extends Entity {
       $module = $stores[$keys[0]]['module'];
       $function = $module . '_vocab_get_term';
       if (function_exists($function)) {
-        $term_details = $function($vocab->namespace, $this->term_id);
+        $term_details = $function($vocab->namespace, $this->accession);
         $this->details = $term_details;
         if ($term_details and $term_details['definition']) {
           $this->definition = $term_details['definition'];

+ 2 - 2
tripal_entities/includes/TripalTermController.inc

@@ -28,7 +28,7 @@ class TripalTermController extends EntityAPIController {
       field_attach_delete('TripalTerm', $entity);
 
       db_delete('tripal_term')
-        ->condition('term_id', $entity->term_id)
+        ->condition('accession', $entity->accession)
         ->execute();
     }
     catch (Exception $e) {
@@ -66,7 +66,7 @@ class TripalTermController extends EntityAPIController {
       // Write out the entity record.
       $record = array(
         'vocab_id' => $entity->vocab_id,
-        'term_id' => $entity->term_id,
+        'accession' => $entity->accession,
         'name' => $entity->name,
         'created' => $entity->created,
         'changed' => time(),

+ 0 - 5
tripal_entities/includes/tripal_entities.admin.inc

@@ -1,6 +1 @@
 <?php
-
-
-
-
-

+ 0 - 194
tripal_entities/includes/tripal_entities.entity_form.inc

@@ -1,194 +0,0 @@
-<?php
-
-/**
- * Provides a list of TripalEntity types (bundles) for the user to add.
- *
- * This function is a callback in a menu item which is set in the
- * TripalEntityUIController class.
- */
-function tripal_entities_add_page() {
-  $item = menu_get_item();
-
-  $content = system_admin_menu_block($item);
-
-  // Bypass the node/add listing if only one content type is available.
-  if (count($content) == 1) {
-    $item = array_shift($content);
-    drupal_goto($item['href']);
-  }
-  return theme('tripal_entities_add_list', array('content' => $content));
-
-}
-
-/**
- * Returns HTML for a list of available node types for node creation.
- *
- * @param $variables
- *   An associative array containing:
- *   - content: An array of content types.
- *
- * @ingroup themeable
- */
-function theme_tripal_entities_add_list($variables) {
-  $content = $variables['content'];
-  $output = '';
-
-  if ($content) {
-    $output = '<dl class="node-type-list">';
-    foreach ($content as $item) {
-      $output .= '<dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>';
-      $output .= '<dd>' . filter_xss_admin($item['description']) . '</dd>';
-    }
-    $output .= '</dl>';
-  }
-  else {
-    $output = tripal_set_message(
-      t('This page is for adding Tripal content to your site. However, before you can add data you have to specify what types of data your site will support. For example, if you want to add genes to be displayed to users, you must first create a data type "gene".'),
-      TRIPAL_INFO,
-      array('return_html' => TRUE)
-    );
-    $output .= '<p>' . t('You have not created any biological data types yet. ' .
-      'Go to the <a href="@create-content">data type creation page</a> to ' .
-      'add a new biological data type.',
-       array('@create-content' => url('admin/structure/bio-data/add'))) . '</p>';
-  }
-  return $output;
-}
-
-/**
- *
- */
-function tripal_entities_entity_form($form, &$form_state, $term_id = '', $entity = NULL) {
-
-  $bundle_name = 'bio-data_' . $term_id;
-
-  // Add a vertical tabs element
-  $form['entity_form_vtabs'] = array(
-    '#type' => 'vertical_tabs',
-    '#weight' => 999,
-  );
-
-  // If the entity doesn't exist then create one.
-  if (!$entity) {
-    $entity = entity_get_controller('TripalEntity')->create(array('bundle' => $bundle_name));
-    field_attach_form('TripalEntity', $entity, $form, $form_state);
-
-    $form['add_button'] = array(
-      '#type' => 'submit',
-      '#value' => t('Save'),
-      '#name' => 'add_data',
-      '#weight' => 1000
-    );
-  }
-  else {
-    field_attach_form('TripalEntity', $entity, $form, $form_state);
-    $form['update_button'] = array(
-      '#type' => 'submit',
-      '#value' => t('Update'),
-      '#name' => 'update_data',
-      '#weight' => 1000
-    );
-    $form['delete_button'] = array(
-      '#type' => 'submit',
-      '#value' => t('Delete'),
-      '#name' => 'delete_data',
-      '#weight' => 1001
-    );
-  }
-
-  // The entity object must be added to the $form_state in order for
-  // the Entity API to work. It must have a key of the entity name.
-  $form_state['TripalEntity'] = $entity;
-
-  $form['#prefix'] = "<div id='$bundle_name-entity-form'>";
-  $form['#suffix'] = "</div>";
-  return $form;
-
-}
-/**
- * An Ajax callback for the tripal_entities_entity_form.
- */
-function tripal_entities_entity_form_ajax_callback($form, $form_state) {
-  // return the form so Drupal can update the content on the page
-  return $form;
-}
-
-/**
- * Implements hook_validate() for the tripal_entities_entity_form.
- */
-function tripal_entities_entity_form_validate($form, &$form_state) {
-
-  if (array_key_exists('clicked_button', $form_state) and
-      $form_state['clicked_button']['#name'] =='add_data') {
-    $entity = $form_state['TripalEntity'];
-    field_attach_form_validate('TripalEntity', $entity, $form, $form_state);
-  }
-}
-
-
-/**
- * Implements hook_submit() for the tripal_entities_entity_form.
- */
-function tripal_entities_entity_form_submit($form, &$form_state) {
-  $entity = $form_state['TripalEntity'];
-
-  if ($form_state['clicked_button']['#name'] =='cancel') {
-    $form_state['redirect'] = "bio-data/" . $entity->id;
-  }
-
-  if ($form_state['clicked_button']['#name'] =='update_data' or
-      $form_state['clicked_button']['#name'] =='add_data') {
-
-    $entityform = entity_ui_controller('TripalEntity')->entityFormSubmitBuildEntity($form, $form_state);
-    if ($entityform->save()) {
-      $form_state['redirect'] = "bio-data/" . $entity->id;
-    }
-    else {
-      drupal_set_message('Cannot save entity', 'error');
-    }
-  }
-  if ($form_state['clicked_button']['#name'] =='delete_data') {
-    $form_state['redirect'] = 'bio-data/' . $entity->id .'/delete';
-  }
-}
-
-/**
- * Form callback: confirmation form for deleting a tripal_entity.
- *
- * @param $tripal_entity The
- *          tripal_entity to delete
- *
- * @see confirm_form()
- */
-function tripal_entities_entity_delete_form($form, &$form_state, $entity) {
-  $form_state['entity'] = $entity;
-  $form['#submit'][] = 'tripal_entities_entity_delete_form_submit';
-
-  $form = confirm_form($form,
-      t('Click the delete button below to confirm deletion of the record titled: %title',
-          array('%title' => $entity->title)), 'admin/content/tripal_entity',
-      '<p>' .t('This action cannot be undone.') .'</p>', t('Delete'), t('Cancel'), 'confirm');
-
-  return $form;
-}
-
-/**
- * Submit callback for tripal_entity_delete_form
- */
-function tripal_entities_entity_delete_form_submit($form, &$form_state) {
-  $entity = $form_state['entity'];
-
-  $entity_controller = new TripalEntityController($entity->type);
-  if ($entity_controller->delete($entity)) {
-    drupal_set_message(t('The record title "%name" has been deleted.', array('%name' => $entity->title)));
-    $form_state['redirect'] = 'admin/content/tripal_entitys';
-  }
-  else {
-    drupal_set_message(t('The tripal_entity %name was not deleted.', array('%name' => $entity->title)), "error");
-  }
-}
-
-
-
-
-

+ 19 - 11
tripal_entities/tripal_entities.install

@@ -13,7 +13,7 @@ function tripal_entities_install() {
   tripal_insert_variable('title_format', 'A pattern including tokens that can be used to generate tripal entity titles.');
   tripal_insert_variable('url_format', 'A pattern including tokens that can be used to generate tripal entity url aliases.');
   tripal_insert_variable('description', 'The description of a Tripal Entity type/bundle.');
-  
+
 }
 
 /**
@@ -26,7 +26,7 @@ function tripal_entities_schema() {
   $schema['tripal_term'] = tripal_entities_tripal_term_schema();
   $schema['tripal_entity'] = tripal_entities_tripal_entity_schema();
   $schema['tripal_bundle'] = tripal_entities_tripal_bundle_schema();
-  
+
   // Adds a table for additional information related to bundles.
   $schema['tripal_bundle_variables'] = tripal_entities_tripal_bundle_variables_schema();
 
@@ -194,7 +194,7 @@ function tripal_entities_tripal_term_schema() {
         'type' => 'int',
         'not null' => TRUE,
       ),
-      'term_id' => array(
+      'accession' => array(
         'description' => 'The id (or accession) of this term in the vocabulary.',
         'type' => 'varchar',
         'length' => 1024,
@@ -223,10 +223,9 @@ function tripal_entities_tripal_term_schema() {
     ),
     'indexes' => array(
       'vocab_id' => array('vocab_id'),
-      'term_id' => array('term_id'),
+      'accession' => array('accession'),
       'entity_changed' => array('changed'),
       'entity_created' => array('created'),
-
     ),
     'foreign keys' => array(
       'tripal_vocab' => array(
@@ -236,7 +235,7 @@ function tripal_entities_tripal_term_schema() {
         ),
       ),
     ),
-    'unique keys' => array('vocab_term' => array('vocab_id', 'term_id')),
+    'unique keys' => array('vocab_term' => array('vocab_id', 'accession')),
     'primary key' => array('id'),
   );
   return $schema;
@@ -260,14 +259,19 @@ function tripal_entities_tripal_bundle_schema() {
         'description' => 'Primary Key: Unique numeric ID.',
       ),
       'type' => array(
-        'description' => 'The type of entity. This should be an official vocabulary ID (e.g. SO, RO, GO).',
+        'description' => 'The type of entity (e.g. TripalEntity).',
         'type' => 'varchar',
         'length' => 64,
         'not null' => TRUE,
         'default' => '',
       ),
-      'bundle' => array(
-        'description' => 'The type of bundle. This should be an official vocabulary ID (e.g. SO, RO, GO) followed by an underscore and the term accession.',
+      'term_id' => array(
+        'description' => 'The term_id for the type of entity. This term_id corresponds to a TripalTerm record.',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'name' => array(
+        'description' => 'The name of the bundle. This should be an official vocabulary ID (e.g. SO, RO, GO) followed by an underscore and the term accession.',
         'type' => 'varchar',
         'length' => 1024,
         'not null' => TRUE,
@@ -281,9 +285,13 @@ function tripal_entities_tripal_bundle_schema() {
         'default' => '',
       ),
     ),
+    'indexes' => array(
+      'name' => array('name'),
+      'term_id' => array('term_id'),
+    ),
     'primary key' => array('id'),
     'unique keys' => array(
-      'bundle' => array('bundle'),
+      'name' => array('name'),
     ),
   );
   return $schema;
@@ -347,7 +355,7 @@ function tripal_entities_tripal_bundle_variables_schema() {
       ),
     ),
   );
-  
+
   return $schema;
 }
 

+ 7 - 10
tripal_entities/tripal_entities.module

@@ -1,7 +1,6 @@
 <?php
 
 require_once "api/tripal_entities.api.inc";
-require_once "includes/tripal_entities.entity_form.inc";
 require_once "includes/TripalVocab.inc";
 require_once "includes/TripalVocabController.inc";
 require_once "includes/TripalTerm.inc";
@@ -175,7 +174,6 @@ function tripal_entities_theme($existing, $type, $theme, $path) {
     ),
     'tripal_entities_add_list' => array(
       'variables' => array('content' => NULL),
-      'file' => 'includes/tripal_entities.entity_form.inc',
     ),
 
   );
@@ -219,6 +217,7 @@ function tripal_entities_rdf_mapping() {
  */
 function tripal_entities_entity_info() {
   $entities = array();
+  //return $entities;
   //
   // The TripalVocab entity is meant to house vocabularies.  It is these
   // vocabs that are used by the TripalTerm entities.  The storage backend
@@ -430,10 +429,9 @@ function tripal_entities_entity_info_alter(&$entity_info){
     $bundles = db_select('tripal_bundle', 'tb')
       ->fields('tb')
       ->execute();
-
     while ($bundle = $bundles->fetchObject()) {
-      $bundle_name = $bundle->bundle;
-      $term_id = preg_replace('/bio-data_/', '', $bundle_name);
+      $bundle_name = $bundle->name;
+      $term_id = $bundle->term_id;
       $term = entity_load('TripalTerm', array('id' => $term_id));
       $term = reset($term);
       $label = preg_replace('/_/', ' ', ucwords($term->name));
@@ -464,14 +462,13 @@ function tripal_entities_entity_info_alter(&$entity_info){
 
 function tripal_bundle_load($bundle_type, $reset = FALSE) {
   // Get the type of entity by the ID.
-  $bundle_types = db_select('tripal_bundle', 'tdt')
+  $bundle = db_select('tripal_bundle', 'tdt')
     ->fields('tdt', array('id', 'type'))
-    ->condition('bundle', $bundle_type)
+    ->condition('name', $bundle_type)
     ->execute()
     ->fetchObject();
-
-  if ($bundle_types) {
-    $entity = entity_load('TripalBundle', array($bundle_types->id), array(), $reset);
+  if ($bundle) {
+    $entity = entity_load('TripalBundle', array($bundle->id), array(), $reset);
     return reset($entity);
   }
   return FALSE;

+ 3 - 3
tripal_fields_layout/tripal_fields_layout.module

@@ -377,7 +377,7 @@ function _tripal_fields_layout_check_default_field_panels($bundle) {
     $fields = db_select('field_config_instance', 'fci')
       ->fields('fci', array('id'))
       ->condition('entity_type', $bundle->type)
-      ->condition('bundle', $bundle->bundle)
+      ->condition('bundle', $bundle->name)
       ->execute();
     foreach($fields AS $field) {
       $penal_field_id = db_select('tripal_panel_fields', 'tpf')
@@ -806,7 +806,7 @@ function tripal_fields_layout_entity_view($entity, $type, $view_mode, $langcode)
 
         $bundle = db_select('tripal_bundle', 'tb')
           ->fields('tb', array('id', 'bundle', 'label'))
-          ->condition('bundle', $entity->bundle)
+          ->condition('name', $entity->name)
           ->execute()
           ->fetchObject();
 
@@ -833,7 +833,7 @@ function tripal_fields_layout_entity_view($entity, $type, $view_mode, $langcode)
 
         // Organize fields into panels
         foreach (element_children($entity->content) as $field_name) {
-          $field_instance = field_info_instance ($type, $field_name, $entity->bundle);
+          $field_instance = field_info_instance ($type, $field_name, $entity->name);
           // Get default panel_id
           $default_panel_id = db_select('tripal_panels', 'tp')
             ->fields('tp', array('panel_id'))

+ 1 - 1
tripal_ws/includes/tripal_ws.rest.inc

@@ -24,7 +24,7 @@ function tripal_ws_rest() {
       ->execute();
     $terms = array();
     while ($bundle = $bundles->fetchObject()) {
-      $cvterm_id = preg_replace('/^bio-data_/', '', $bundle->bundle);
+      $cvterm_id = preg_replace('/^bio-data_/', '', $bundle->name);
       if ($cvterm_id) {
         $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
         $terms[$cvterm->name] = $cvterm;