Quellcode durchsuchen

Creation of new entities using new TripalTerm, TripalVocab, with all Chado quereis moved to tripal_chado module... is now working!

Stephen Ficklin vor 9 Jahren
Ursprung
Commit
1dd17d14c7

+ 43 - 43
tripal_chado/api/tripal_chado.api.inc

@@ -30,52 +30,52 @@
  */
 function tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_id) {
 
-      $field = field_info_field($field_name);
+  $field = field_info_field($field_name);
 
-      // If the field exists and is attached to this bundle then just return,
-      // 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])) {
-            return;
-          }
+  // If the field exists and is attached to this bundle then just return,
+  // 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])) {
+    return;
+  }
 
-          // Allow other modules to alter the field information array.
-          drupal_alter('chado_field', $field_info);
+  // Allow other modules to alter the field information array.
+  drupal_alter('chado_field', $field_info);
 
-          $cardinality = 1;
-          if (array_key_exists('cardinality', $field_info) and is_numeric($field_info['cardinality'])) {
-            $cardinality = $field_info['cardinality'];
-          }
+  $cardinality = 1;
+  if (array_key_exists('cardinality', $field_info) and is_numeric($field_info['cardinality'])) {
+    $cardinality = $field_info['cardinality'];
+  }
 
-          // If the field doesn't exist then create it.
-          if (!$field) {
-            $field = array(
-              'field_name' => $field_name,
-              'type' => $field_info['field_type'],
-              'cardinality' => $cardinality,
-              'locked' => FALSE,
-              'storage' => array(
-                'type' => 'field_chado_storage'
-              ),
-              'settings' => $field_info['field_settings'],
-            );
-            field_create_field($field);
-          }
+  // If the field doesn't exist then create it.
+  if (!$field) {
+    $field = array(
+      'field_name' => $field_name,
+      'type' => $field_info['field_type'],
+      'cardinality' => $cardinality,
+      'locked' => FALSE,
+      'storage' => array(
+        'type' => 'field_chado_storage'
+      ),
+      'settings' => $field_info['field_settings'],
+    );
+    field_create_field($field);
+  }
 
-          // Attach the field to the bundle.
-          $field_instance = array(
-            'field_name' => $field_name,
-            'label' => $field_info['label'],
-            'description' => $field_info['description'],
-            'widget' => array(
-              'type' => $field_info['widget_type'],
-              'settings' => $field_info['widget_settings'],
-            ),
-            'entity_type' => $entity_type_name,
-            'required' => $field_info['is_required'],
-            'settings' => $field_info['field_settings'],
-            'bundle' => $bundle_id,
-          );
-          field_create_instance($field_instance);
+  // Attach the field to the bundle.
+  $field_instance = array(
+    'field_name' => $field_name,
+    'label' => $field_info['label'],
+    'description' => $field_info['description'],
+    'widget' => array(
+      'type' => $field_info['widget_type'],
+      'settings' => $field_info['widget_settings'],
+    ),
+    'entity_type' => $entity_type_name,
+    'required' => $field_info['is_required'],
+    'settings' => $field_info['field_settings'],
+    'bundle' => $bundle_id,
+  );
+  field_create_instance($field_instance);
 }

+ 22 - 5
tripal_chado/includes/fields/kvproperty.inc

@@ -43,6 +43,19 @@ 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));
   $matches = array();
   preg_match('/(.*?)__(\d+)/', $field_name, $matches);
   // If the field name is not properly formatted then we can't tell what
@@ -57,8 +70,8 @@ function tripal_chado_kvproperty_widget(&$widget, $form, $form_state, $field, $i
   // of the FK field that links to the base table.
   $schema = chado_get_schema($table_name);
   $pkey = $schema['primary key'][0];
-  $lfkey_field = key($schema['foreign keys'][$entity->chado_table]['columns']);
-  $rfkey_field = $schema['foreign keys'][$entity->chado_table]['columns'][$lfkey_field];
+  $lfkey_field = key($schema['foreign keys'][$chado_table]['columns']);
+  $rfkey_field = $schema['foreign keys'][$chado_table]['columns'][$lfkey_field];
 
   // Get the field defaults.
   $fk_value = '';
@@ -66,8 +79,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 (property_exists($entity, 'chado_record')) {
-    $fk_value = $entity->chado_record->$rfkey_field;
+  if (count($record) > 0) {
+    $fk_value = $record[0]->$rfkey_field;
   }
 
 
@@ -123,6 +136,10 @@ 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 table name and cvterm_id for this field.
   preg_match('/(.*?)__(\d+)/', $field_name, $matches);
   $table_name = $matches[1];
@@ -132,7 +149,7 @@ function tripal_chado_kvproperty_widget_validate($element, &$form_state) {
   // of the FK field that links to the base table.
   $schema = chado_get_schema($table_name);
   $pkey = $schema['primary key'][0];
-  $lfkey_field = key($schema['foreign keys'][$entity->chado_table]['columns']);
+  $lfkey_field = key($schema['foreign keys'][$chado_table]['columns']);
 
   // If we don't have a property value then we need to set all other fields
   // to be empty so that when the module tries to save the field on the

+ 12 - 0
tripal_chado/includes/tripal_chado.entity.inc

@@ -24,7 +24,15 @@ function tripal_chado_entity_postsave($entity, $type) {
  * Implements hook_entity_load().
  */
 function tripal_chado_entity_load($entities, $type) {
+  dpm($entities);
 
+  // Set some information about the entity about it's Chado record.
+  foreach ($entities as $entity) {
+    dpm($entity->type);
+    if ($entity->type == 'TripalEntity') {
+
+    }
+  }
 }
 
 /**
@@ -92,6 +100,10 @@ function theme_tripal_chado_date_combo($variables) {
 /**
  * Determines whether the given user has access to a tripal data entity.
  *
+ * TODO: I'm not sure this function should be at this level. I think all
+ * access controls should be handled by the tripal_entity module and that
+ * storage backends should just attach data as requested.
+ *
  * @param $op
  *   The operation being performed. One of 'view', 'update', 'create', 'delete'
  *   or just 'edit' (being the same as 'create' or 'update').

+ 27 - 19
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -13,29 +13,37 @@ function tripal_chado_field_storage_info() {
   );
 }
 
-/**
- * Implements hook_field_storage_query().
- *
- * @param $query
- */
-function tripal_chado_field_storage_query($query) {
-  // TODO: figure out what this function does.
-}
 /**
  * Implements hook_field_storage_write().
  */
 function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
 
+  // Get the bundle and the term for this entity.
+  $bundle = tripal_load_bundle_entity($entity->bundle);
+  $term = entity_load('TripalTerm', array('id' => $entity->term_id));
+  $term = reset($term);
+
   // Get the base table, type field and record_id from the entity.
-  $base_table = $entity->chado_table;
-  $type_field = $entity->chado_field;
-  $record_id  = property_exists($entity, 'chado_record_id') ? $entity->chado_record_id : NULL;
+  $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;
+  }
 
   // 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);
 
   // Recursively write fields for the base table.
-  $record_id = tripal_chado_field_storage_write_recursive($entity_type, $entity,
+  $record_id = tripal_chado_field_storage_write_recursive($entity_type, $entity, $term,
       $op, $field_vals, $base_table, $base_table, $type_field, $record_id);
 
   // If this is an insert then add the chado_entity record.
@@ -45,9 +53,9 @@ function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
     $record = array(
       'entity_id' => $entity->id,
       'record_id' => $record_id,
-      'data_table' => $entity->chado_table,
-      'type_table' => $entity->chado_table,
-      'field' => $entity->chado_field,
+      'data_table' => $base_table,
+      'type_table' => $base_table,
+      'field' => $type_field,
     );
     $success = drupal_write_record('chado_entity', $record);
     if (!$success) {
@@ -71,7 +79,7 @@ function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
 
         // Iterate through each record.
         foreach ($field_vals[$field_name] as $delta => $fvals) {
-          tripal_chado_field_storage_write_recursive($entity_type, $entity,
+          tripal_chado_field_storage_write_recursive($entity_type, $entity, $term,
               $op, $fvals, $base_table, $field_table);
         }
       }
@@ -93,7 +101,7 @@ function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
  * @return
  *   The record_id of the table if a matching record exists.
  */
-function tripal_chado_field_storage_write_recursive($entity_type, $entity,
+function tripal_chado_field_storage_write_recursive($entity_type, $entity, $term,
    $op, $field_vals, $base_table, $tablename, $type_field = NULL,
    $record_id = NULL, $depth = 0) {
 
@@ -115,7 +123,7 @@ function tripal_chado_field_storage_write_recursive($entity_type, $entity,
 
       // If this is the base table then do not recurse on the type_id.
       if ($tablename == $base_table && $local_id == $type_field) {
-        $values[$local_id] = $entity->cvterm_id;
+        $values[$local_id] = $term->details['cvterm']->cvterm_id;
         continue;
       }
 
@@ -155,7 +163,7 @@ function tripal_chado_field_storage_write_recursive($entity_type, $entity,
       // Recurse on the FK field.  Pass in the ID for the FK field if one
       // exists in the $field_vals;
       $fk_val = tripal_chado_field_storage_write_recursive($entity_type,
-        $entity, $op, $fk_vals, $base_table, $fk_table, NULL, $fk_val, $depth + 1);
+        $entity, $term, $op, $fk_vals, $base_table, $fk_table, NULL, $fk_val, $depth + 1);
       if (isset($fk_val) and $fk_val != '' and $fk_val != 0) {
         $values[$local_id] = $fk_val;
       }

+ 41 - 0
tripal_chado/includes/tripal_chado.term_storage.inc

@@ -13,6 +13,47 @@ function tripal_chado_vocab_storage_info() {
   );
 }
 
+/**
+ * Implements hook_vocab_get_term().
+ *
+ * This hooks 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 $term_id
+ *   The unique identifier (accession) for this term.
+ *
+ * @return
+ *   An array with at least the following keys:
+ *     id : 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) {
+  $match = array(
+    'dbxref_id' => array(
+      'db_id' => array(
+        'name' => $namespace,
+      ),
+      'accession' => $term_id
+    ),
+  );
+  $cvterm = chado_generate_var('cvterm', $match);
+  if (!$cvterm) {
+    return NULL;
+  }
+  $cvterm = chado_expand_var($cvterm, 'field', 'cveterm.definition');
+  return array(
+    'id' => $cvterm->dbxref_id->accession,
+    'name' => $cvterm->name,
+    'definition' => $cvterm->definition,
+    'cvterm' => $cvterm,
+  );
+}
 /**
  * Implements hook_vocab_select_term_form().
  */

+ 7 - 0
tripal_chado/tripal_chado.install

@@ -40,6 +40,13 @@ function tripal_chado_install() {
     'cv_name' => 'local',
   ));
 
+  // For the TripalBundle entities we will want to associate the cvterm_id,
+  // and the chado table and field that it maps to.  We will use a few
+  // variables to do this:
+  tripal_insert_variable('chado_cvterm_id', 'The cvterm_id that a TripalBundle maps to.');
+  tripal_insert_variable('chado_table', 'The name of the table to which a TripalBundle maps.');
+  tripal_insert_variable('chado_column', 'The name of the column within the table that a TripalBundle maps to.');
+
   // We want to provide a set of commonly used entity types by default. This
   // way when a user first installs Tripal there are some commonly used
   // formats.

+ 16 - 17
tripal_chado/tripal_chado.module

@@ -523,17 +523,10 @@ function tripal_chado_theme($existing, $type, $theme, $path) {
 
 /**
  * Implements hook_add_bundle_fields().
- *
- * @param $entity_type
- *   The entity type (e.g. TripalEntity).
- * @param $bundle_id
- *   The bundle ID.
- * @param $term
- *   An instance of a TripalTerm object.
- * @return
- *   TRUE on success, FALSE on failure.
  */
-function tripal_chado_add_bundle_fields($entity_type, $bundle_id, $term) {
+function tripal_chado_add_bundle_fields($entity_type, $bundle, $term) {
+
+  $bundle_name = $bundle->bundle;
 
   // This array will hold details that map the bundle to tables in Chado.
   $bundle_data = array();
@@ -603,21 +596,27 @@ function tripal_chado_add_bundle_fields($entity_type, $bundle_id, $term) {
   }
 
   // Adds the fields for the base table to the entity.
-  tripal_chado_add_bundle_base_fields($entity_type, $bundle_id, $bundle_data);
+  tripal_chado_add_bundle_base_fields($entity_type, $bundle_name, $bundle_data);
+
+  // Save the mapping information so that we can reuse it when we need to
+  // look things up for later for an entity
+  tripal_set_bundle_variable('chado_cvterm_id', $bundle->id, $bundle_data['cvterm_id']);
+  tripal_set_bundle_variable('chado_table', $bundle->id, $bundle_data['data_table']);
+  tripal_set_bundle_variable('chado_column', $bundle->id, $bundle_data['field']);
 
   // Check to see if there are any kv-property tables associated to this
   // base table. If so, add the fields for that type of table.
-  tripal_chado_add_bundle_kvproperty_adder_field($entity_type, $bundle_id, 'featureprop');
+  tripal_chado_add_bundle_kvproperty_adder_field($entity_type, $bundle_name, 'featureprop');
 }
 
 /**
  * Adds the fields for a kv-property table fields
  *
  * @param $entity_type_name
- * @param $bundle_id
+ * @param $bundle_name
  * @param $kv_table
  */
-function tripal_chado_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_id, $kv_table) {
+function tripal_chado_add_bundle_kvproperty_adder_field($entity_type_name, $bundle_name, $kv_table) {
   // First add a generic property field so that users can add new proeprty types.
   $field_name = $kv_table;
 
@@ -631,13 +630,13 @@ function tripal_chado_add_bundle_kvproperty_adder_field($entity_type_name, $bund
     'label' => 'Additional Properties',
     'is_required' => 0,
   );
-  tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_id);
+  tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
 }
 
 /**
  * Adds the fields for the base table to the entity.
  */
-function tripal_chado_add_bundle_base_fields($entity_type_name, $bundle_id, $bundle_data) {
+function tripal_chado_add_bundle_base_fields($entity_type_name, $bundle_name, $bundle_data) {
 
   $table_name = $bundle_data['data_table'];
   $type_table = $bundle_data['type_table'];
@@ -692,7 +691,7 @@ function tripal_chado_add_bundle_base_fields($entity_type_name, $bundle_id, $bun
     }
 
     // Add the field to the bundle.
-    tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_id);
+    tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
   }
 }
 

+ 35 - 35
tripal_core/api/tripal_core.tripal_variables.api.inc

@@ -1,7 +1,7 @@
 <?php
 /**
  * @file
- * Provides an application programming interface (API) for managing variables 
+ * Provides an application programming interface (API) for managing variables
  * associated with Tripal managed Drupal nodes/
  */
 
@@ -9,14 +9,14 @@
  * @defgroup tripal_variables_api Tripal Variables API
  * @ingroup tripal_core_api
  * @{
- * Provides an application programming interface (API) for managing variables 
- * associated with Tripal managed Drupal nodes. The Tripal Variables API 
- * supports storing any type of variable such as a property or setting that 
+ * Provides an application programming interface (API) for managing variables
+ * associated with Tripal managed Drupal nodes. The Tripal Variables API
+ * supports storing any type of variable such as a property or setting that
  * should be associated with a Tripal managed Drupal node.  Variables are
- * meant to store non-biological information only. All biological data should be 
- * housed in the Chado tables. Be aware that any data stored as a Tripal 
- * Variable will not be made visible through services such as Tripal Web 
- * Services and therefore can be a good place to hide application specific 
+ * meant to store non-biological information only. All biological data should be
+ * housed in the Chado tables. Be aware that any data stored as a Tripal
+ * Variable will not be made visible through services such as Tripal Web
+ * Services and therefore can be a good place to hide application specific
  * settings
  * @}
  *
@@ -24,13 +24,13 @@
 
 /**
  * Adds a new variable name.
- * 
+ *
  * @param $name
  *   The name of the variable
  * @param $description
  *   The description for the variable
- * @return 
- *   A record object containg the variable that was added if successful. 
+ * @return
+ *   A record object containg the variable that was added if successful.
  */
 function tripal_insert_variable($name, $description) {
   $name = trim($name);
@@ -44,7 +44,7 @@ function tripal_insert_variable($name, $description) {
         'Must have a description when adding a new Tripal Variable.', array());
     return NULL;
   }
-  
+
   // Make sure the variable is not a duplicate. If so, then just select
   // it and return the variable_id
   $variable = tripal_get_variable($name);
@@ -64,10 +64,10 @@ function tripal_insert_variable($name, $description) {
 
 /**
  * Retrieves the variable name record.
- * 
+ *
  * @param $name
  *   The name of the variable to retrieve
- * @return 
+ * @return
  *   A record object containg the variable.
  */
 function tripal_get_variable($name) {
@@ -80,17 +80,17 @@ function tripal_get_variable($name) {
 
 /**
  * Associates a variable and it's value to a node.
- * 
+ *
  * If a variable is already associated more with a node then the rank value
  * is used to differentiate them.  By default the rank is set to 0 and can
  * be manually set by using the $rank argument.  But, if left unspecified
  * the next available rank will automatically be used.
- * 
- * If the variable does not exist then it will be added automatically to 
- * prevent errors. However, modules developers should always add their 
+ *
+ * If the variable does not exist then it will be added automatically to
+ * prevent errors. However, modules developers should always add their
  * variables first before using. If the variable already exists then it
- * will simply be re-used. 
- * 
+ * will simply be re-used.
+ *
  * @param $nid
  *   The node ID.
  * @param $name
@@ -98,22 +98,22 @@ function tripal_get_variable($name) {
  * @param $value
  *   The value of the variable.
  * @param $rank
- *   The rank of the value. Default to zero.  
- * 
+ *   The rank of the value. Default to zero.
+ *
  * @return TRUE|FALSE
- *   Returns TRUE if the variable was associated with the node and false if 
+ *   Returns TRUE if the variable was associated with the node and false if
  *   a failure occured.
  */
 function tripal_add_node_variable($nid, $name, $value, $rank = 0) {
-  
-  // Make sure the variable exists. To prevent unwanted errors from 
+
+  // Make sure the variable exists. To prevent unwanted errors from
   // umet dependencies (e.g. modules using other modules' variables) the variable
   // will be created automatically if it is missing.
   $variable = tripal_get_variable($name);
   if (!$variable) {
     $variable = tripal_insert_variable($name, "Added automatically. Please describe this variable.");
   }
-  
+
   // Is the variable already associated with this node? If so, then find the
   // next avilable rank. If the $update_existing variable is true then just
   // update the record.
@@ -136,7 +136,7 @@ function tripal_add_node_variable($nid, $name, $value, $rank = 0) {
     }
     $rank = $max_rank++;
   }
-  
+
   // Add the new variable.
   $node_variable_id = db_insert('tripal_node_variables')
     ->fields(array(
@@ -148,14 +148,14 @@ function tripal_add_node_variable($nid, $name, $value, $rank = 0) {
      ->execute();
   return $node_variable_id;
 }
- 
+
 /**
  * Returns one or more variables assigned to a node.
- * 
- * An array is returned containing an object for each variable assigned 
+ *
+ * An array is returned containing an object for each variable assigned
  * to a term that matches the criteria.  If a name and rank are provided then
  * the variables returned must match.
- * 
+ *
  * @param $nid
  *   The node ID
  * @param $name
@@ -181,7 +181,7 @@ function tripal_get_node_variables($nid, $name = '', $rank = '') {
     $query->condition('rank', $rank, '=');
   }
   $results = $query->execute();
-  
+
   // Build the  variables array and return it.
   while($variable = $results->fetchObject()) {
     $variables[] = $variable;
@@ -191,15 +191,15 @@ function tripal_get_node_variables($nid, $name = '', $rank = '') {
 
 /**
  * Removes variables assigned to a node.
- * 
+ *
  * @param $nid
  *   The node ID
  * @param $name
  *   Optional.  The name of the variable.
  * @param $rank
  *   Optional.  The rank of the variable to retreive.
- *   
- * @return 
+ *
+ * @return
  *   Return TRUE if deletion is successful, FALSE otherwise.
  */
 function tripal_delete_node_variables($nid, $name = '', $rank = '') {

+ 220 - 40
tripal_entities/api/tripal_entities.api.inc

@@ -47,6 +47,29 @@ function tripal_load_vocab_entity($namespace) {
   }
   return NULL;
 }
+
+/**
+ * Retrieves a TripalBundle entity that matches the given arguments.
+ *
+ * @param $name
+ *   The name the bundle (e.g. bio-data_234).
+ *
+ * @return
+ *   A TripalBundle entity object or NULL if not found.
+ */
+function tripal_load_bundle_entity($name) {
+  $bundle = db_select('tripal_bundle', 'tb')
+    ->fields('tb')
+    ->condition('tb.bundle', $name)
+    ->execute()
+    ->fetchObject();
+
+  if ($bundle) {
+    $entity = entity_load('TripalBundle', array($bundle->id));
+    return reset($entity);
+  }
+  return NULL;
+}
 /**
  * Creates a new Tripal Entity type (i.e. bundle).
  *
@@ -82,12 +105,11 @@ function tripal_create_bundle($namespace, $term_id, $term_name, &$error = '') {
     $term = $term->save();
   }
 
-
   // If the bundle doesn't already exist, then add it.
   $bundle_id = 'bio-data_' . $term->id;
   $einfo = entity_get_info('TripalEntity');
   if (!in_array($bundle_id, array_keys($einfo['bundles']))) {
-    // Inser the bundle.
+    // Insert the bundle.
     db_insert('tripal_bundle')
       ->fields(array(
         'label' => $term_name,
@@ -104,67 +126,107 @@ function tripal_create_bundle($namespace, $term_id, $term_name, &$error = '') {
   cache_clear_all("entity_info:$langcode", 'cache');
   variable_set('menu_rebuild_needed', TRUE);
 
+  // Get the bundle object.
+  $bundle = tripal_load_bundle_entity($bundle_id);
+
   // Allow modules to now add fields to the bundle
-  module_invoke_all('add_bundle_fields', 'TripalEntity', $bundle_id, $term);
+  module_invoke_all('add_bundle_fields', 'TripalEntity', $bundle, $term);
 
   return TRUE;
 }
 
 /**
- * Get Page Title Format for a given Tripal Entity Type.
+ * Allows a module to add fields to a bundle.
  *
- * @param TripalBundle $entity
- *   The Entity object for the Tripal Bundle the title format is for.
+ * This function is called after the bundle is created and allows any module
+ * to add fields to it.
+ *
+ * @param $entity_type
+ *   The entity type (e.g. TripalEntity).
+ * @param $bundle
+ *   A TripalBundle object.
+ * @param $term
+ *   An instance of a TripalTerm object.
+ *
+ * @return
+ *   TRUE on success, FALSE on failure.
  */
-function tripal_get_title_format($entity) {
+function hook_add_bundle_fields($entity_type, $bundle, $term) {
 
-  // Title formats are saved as Tripal Bundle Variables.
-  // Therefore, first we need the variable_id for title_formats.
-  $variable_id = db_select('tripal_variables', 'v')
-    ->fields('v', array('variable_id'))
-    ->condition('name', 'title_format')
-    ->execute()
-    ->fetchField();
+}
+
+/**
+ * @section
+ * Bundle Variables.
+ */
+
+/**
+ * Fetch the value for a given tripal variable.
+ *
+ * @param string $variable_name
+ *   The name of the variable as in tripal_variables.name.
+ * @param int $bundle_id
+ *   The unique identfier for the bundle you want the value for.
+ * @return text
+ *   The value of the specified variable for the specified bundle.
+ */
+function tripal_get_bundle_variable($variable_name, $bundle_id, $default = FALSE) {
+
+  $variable = tripal_get_variable($variable_name);
+
+  // Warn if we can't find the tripal_variable.
+  if (!$variable) {
+//     tripal_report_error(
+//       'trpbundle_var',
+//       TRIPAL_WARNING,
+//       'Unable to fetch tripal bundle variable value due to missing tripal variable (%var).',
+//       array('%var' => $variable_name)
+//     );
+//     return FALSE;
+    return $default;
+  }
 
-  // Then we can check if there is already a title format for this bundle/type.
-  $title_format = db_select('tripal_bundle_variables', 'var')
+  // Select the value for this variable.
+  $value = db_select('tripal_bundle_variables', 'var')
     ->fields('var', array('value'))
-    ->condition('var.bundle_id', $entity->id)
-    ->condition('var.variable_id', $variable_id)
+    ->condition('var.bundle_id', $bundle_id)
+    ->condition('var.variable_id', $variable->variable_id)
     ->execute()
     ->fetchField();
 
-  // If there isn't yet a title format for this bundle/type then we should
-  // determine the default based on the table unique constraint and save it.
-  // @TODO: Replace the label with the base table name.
-  // @TODO: make this chado independant.
-  if (!$title_format) {
-    $title_format = chado_node_get_unique_constraint_format($entity->label);
-    tripal_save_title_format($entity, $title_format);
+  // Warn if the value appears to be empty.
+  if (!$value) {
+//     tripal_report_error(
+//       'trpbundle_var',
+//       TRIPAL_WARNING,
+//       'Unable to fetch tripal bundle variable (%var) value.',
+//       array('%var' => $variable_name)
+//     );
+    return $default;
   }
 
-  return $title_format;
+  return $value;
 }
 
 /**
- * Save Page Title Format for a given Tripal Entity Type.
+ * Save the value of a tripal variable for a given bundle.
  *
- * @param TripalBundle $entity
- *   The Entity object for the Tripal Bundle the title format is for.
- * @param string $format
- *   The pattern to be used when generating entity titles for the above type.
+ * @param string $variable_name
+ *   The name of the variable as in tripal_variables.name.
+ * @param int $bundle_id
+ *   The unique identfier for the bundle you want the value for.
+ * @param $text $value
+ *   The value of the variable for the given bundle.
  */
-function tripal_save_title_format($entity, $format) {
+function tripal_set_bundle_variable($variable_name, $bundle_id, $value) {
 
-  // Title formats are saved as Tripal Bundle Variables.
-  // Thus first we need to grab the variable_id for title_format.
-  $variable_id = db_select('tripal_variables', 'v')->fields('v', array('variable_id'))->condition('name', 'title_format')->execute()->fetchField();
+  $variable = tripal_get_variable($variable_name);
 
   // And then we need to write the new format to the tripal_bundle_variables table.
   $record = array(
-    'bundle_id' => $entity->id,
-    'variable_id' => $variable_id,
-    'value' => $format,
+    'bundle_id' => $bundle_id,
+    'variable_id' => $variable->variable_id,
+    'value' => $value,
   );
 
   // Check whether there is already a format saved.
@@ -176,14 +238,132 @@ function tripal_save_title_format($entity, $format) {
     ->fetchField();
   if ($bundle_variable_id) {
     $record['bundle_variable_id'] = $bundle_variable_id;
-    drupal_write_record('tripal_bundle_variables', $record, 'bundle_variable_id');
+    return drupal_write_record('tripal_bundle_variables', $record, 'bundle_variable_id');
   }
   else {
-    drupal_write_record('tripal_bundle_variables', $record);
+    return drupal_write_record('tripal_bundle_variables', $record);
+  }
+
+}
+
+/**
+ * @section
+ * Title & URL Formats.
+ */
+
+/**
+ * Get Page Title Format for a given Tripal Entity Type.
+ *
+ * @param TripalBundle $entity
+ *   The Entity object for the Tripal Bundle the title format is for.
+ */
+function tripal_get_title_format($entity) {
+
+  // Get the existing title format if it exists.
+  $title_format = tripal_get_bundle_variable('title_format', $entity->id);
+
+  // If there isn't yet a title format for this bundle/type then we should
+  // determine the default.
+  if (!$title_format) {
+    $title_format = tripal_get_default_title_format($entity);
+    tripal_save_title_format($entity, $title_format);
+  }
+
+  return $title_format;
+}
+
+/**
+ * Save Page Title Format for a given Tripal Entity Type.
+ *
+ * @param TripalBundle $entity
+ *   The Entity object for the Tripal Bundle the title format is for.
+ * @param string $format
+ *   The pattern to be used when generating entity titles for the above type.
+ */
+function tripal_save_title_format($entity, $format) {
+
+  return tripal_bundle_save_variable('title_format', $entity->id, $format);
+}
+
+/**
+ * Determine the default pattern/format to use for an entity type.
+ *
+ * @param TripalBundle $entity
+ *   The Entity object for the Tripal Bundle the title format is for.
+ * @return string
+ *   A default title format.
+ */
+function tripal_get_default_title_format($entity) {
+  $format = array();
+
+  // Retrieve all available tokens.
+  $tokens = tripal_get_tokens($entity);
+
+  foreach($tokens as $token) {
+    if ($token['required']) {
+      $format[] = $token['token'];
+    }
+  }
+
+  return implode(', ', $format);
+}
+
+/**
+ * Returns an array of tokens based on Tripal Entity Fields.
+ *
+ * @param TripalBundle $entity
+ *    The bundle entity for which you want tokens.
+ * @return
+ *    An array of tokens where the key is the machine_name of the token.
+ */
+function tripal_get_tokens($entity) {
+  $tokens = array();
+
+  $fields = field_info_instances('TripalEntity', $entity->bundle);
+  foreach ($fields as $f) {
+
+    // Build the token from the field information.
+    $token = '[' . $f['field_name'] . ']';
+    $tokens[$token] = array(
+      'label' => $f['label'],
+      'description' => $f['description'],
+      'token' => $token,
+      'field_name' => $f['field_name'],
+      'required' => $f['required']
+    );
+  }
+
+  return $tokens;
+}
+
+/**
+ * Formats the tokens for display.
+ *
+ * @param array $tokens
+ *   A list of tokens generated via tripal_get_tokens().
+ * @return
+ *   Rendered output describing the available tokens.
+ */
+function theme_token_list($tokens) {
+
+  $header = array('Token', 'Name', 'Description');
+  $rows = array();
+  foreach ($tokens as $details) {
+    $rows[] = array(
+      '[' . $details['field_name'] . ']',
+      $details['label'],
+      $details['description'],
+    );
   }
 
+  return theme('table', array('header' => $header, 'rows' => $rows));
 }
 
+/**
+ * @section
+ * Vocabulary Hooks.
+ */
+
 /**
  * A hook for specifying information about the data store for vocabularies.
  *

+ 75 - 45
tripal_entities/includes/TripalBundleUIController.inc

@@ -18,7 +18,7 @@ class TripalBundleUIController extends EntityDefaultUIController {
    */
   public function hook_menu() {
     $items = parent::hook_menu();
-    
+
     // Alter the Admin > Structure > Tripal Content Types menu item.
     $items[$this->path]['description'] = 'Manage biological content types that are
       added using Tripal.';
@@ -38,7 +38,7 @@ class TripalBundleUIController extends EntityDefaultUIController {
       'type' => MENU_LOCAL_ACTION,
       'weight' => 2
     );
-    
+
     return $items;
   }
 
@@ -58,7 +58,7 @@ class TripalBundleUIController extends EntityDefaultUIController {
 
     return $forms;
   }
-  
+
 }
 
 /**
@@ -74,43 +74,67 @@ class TripalBundleUIController extends EntityDefaultUIController {
 function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType) {
 
   $entity_type = $form_state['build_info']['args'][0];
-  $chado_basetable = $entity_type->label;
-  $cvterm = chado_generate_var('cvterm', array('name' => $entity_type->label));
-  
+  if (preg_match('/bio-data_(\d+)/', $entity_type->term_id, $matches)) {
+    $term = entity_load('TripalTerm', array('id' => $entity_type->term_id));
+    $term = reset($term);
+    $vocab = entity_load('TripalVocab', array('id' => $term->vocab_id));
+    $vocab = reset($vocab);
+  }
+
   // Add a validate and submit handler to save the data in this form.
   $form['#validate'] = array('tripal_entities_tripal_bundle_form_validate');
   $form['#submit'] = array('tripal_entities_tripal_bundle_form_submit');
-  
+
   // @TODO: Move this into a css file.
   $form['#attached']['css'] = array(
     array(
-      'data' => '.form-item select, .form-item input { width:40%; }',
+      'data' => '
+        .form-item select, .form-item input { width:40%; }
+        th.side-header { width: 220px; }',
       'type' => 'inline',
     ),
   );
-  
-  $form['vocab'] = array(
-    '#type' => 'select',
-    '#title' => t('Vocabulary'),
-    '#options' => array($cvterm->cv_id->name),
-    '#description' => t('The vocabulary the following term is part of.'),
-    '#default_value' => $cvterm->cv_id->name,
-    '#disabled' => TRUE  
-  );
-  
-  $form['term'] = array(
+
+    if ($term) {
+    $form['term'] = array(
+      '#type' => 'markup',
+      '#markup' => theme('table', array(
+        'header' => array(),
+        'rows' => array(
+          array(array('header' => TRUE, 'data' => 'Vocabulary', 'class' => array('side-header')), $vocab->namespace),
+          array(array('header' => TRUE, 'data' => 'Term', 'class' => array('side-header')), $term->name),
+        )
+      ))
+    );
+  }
+
+  $form['label'] = array(
     '#type' => 'textfield',
-    '#title' => t('Term'),
-    '#description' => t('The term the content type is based on.'),
-    '#default_value' => $cvterm->name,
-    '#disabled' => TRUE  
+    '#title' => t('Name'),
+    '#required' => TRUE,
+    '#description' => t('The human-readable name of this content type. This text will be
+      displayed as part of the list on the <em>Add new content page</em>. It is recommended that
+      this name begin with a capital letter and contain only letters, numbers, and spaces.
+      This name must be unique.'),
+    '#default_value' => $entity_type->label,
+  );
+
+  $form['description'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Description'),
+    '#required' => TRUE,
+    '#description' => t('Describe this content type. The text will be displayed on the <em>Add new content page</em>.'),
+    '#default_value' => tripal_get_bundle_variable('description', $entity_type->id, $term->definition),
   );
-  
+  if (!$form['description']['#default_value']) {
+    //$form['description']['#default_value'] = $cvterm->definition;
+  }
+
   $form['additional_settings'] = array(
     '#type' => 'vertical_tabs',
     '#weight' => 99,
   );
-  
+
   // Set Title Format.
   //-------------------------
   $title_format = tripal_get_title_format($entity_type);
@@ -123,12 +147,12 @@ function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType
     '#tree' => TRUE,
     '#group' => 'additional_settings',
   );
-  
+
   $form['set_titles']['explanation'] = array(
     '#type' => 'item',
-    '#markup' => t('<p>The format below is used to determine the title displayed on content 
-      pages. This ensures all content of this type is consistent while still allowing you 
-      to indicate which data you want represented in the title (ie: which data would most 
+    '#markup' => t('<p>The format below is used to determine the title displayed on content
+      pages. This ensures all content of this type is consistent while still allowing you
+      to indicate which data you want represented in the title (ie: which data would most
       identify your content).</p>
       <p>Keep in mind that it might be confusing to users if more than
       one page has the same title. We recommend you <strong>choose a combination of tokens that
@@ -141,6 +165,7 @@ function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType
     '#description' => t('You may rearrange elements in this text box to customize the page
       titles. The available tokens are listed below. You can separate or include any text
       between the tokens.'),
+    '#required' => TRUE,
     '#default_value' => $title_format,
     '#rows' => 1
   );
@@ -153,30 +178,26 @@ function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType
     '#collapsed' => TRUE
   );
 
-  $tokens = array();
-  if (empty($tokens)) {
-    $tokens = chado_node_generate_tokens($chado_basetable);
-  }
+  $tokens = tripal_get_tokens($entity_type);
   $form['set_titles']['tokens'] = array(
     '#type' => 'hidden',
     '#value' => serialize($tokens)
   );
-  
-  $token_list = chado_node_format_tokens($tokens);
+
   $form['set_titles']['token_display']['content'] = array(
     '#type' => 'item',
-    '#markup' => $token_list
+    '#markup' => theme_token_list($tokens)
   );
 
   // Submit Buttons
   //-------------------------
-  
+
   $form['save'] = array(
     '#type' => 'submit',
     '#value' => t('Save Content Type'),
     '#weight' => 100
   );
-  
+
   $form['delete'] = array(
     '#type' => 'submit',
     '#value' => t('Delete Content Type'),
@@ -192,19 +213,19 @@ function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType
 function tripal_entities_tripal_bundle_form_validate($form, $form_state) {
 
   $tokens_available = unserialize($form_state['values']['set_titles']['tokens']);
-  if (preg_match_all('/(\[\w+\.\w+\])/', $form_state['values']['set_titles']['title_format'], $matches)) {
-    
+  if (preg_match_all('/(\[\w+\])/', $form_state['values']['set_titles']['title_format'], $matches)) {
+
     // The matches of the first and only pattern will be our tokens.
     $tokens_used = $matches[1];
     // Determine if any of the tokens used were not in the original list of available tokens.
     $tokens_missing = array_diff($tokens_used, array_keys($tokens_available));
-    
+
     if ($tokens_missing) {
       $msg = t('You must only use tokens listed under available tokens. You used the following incorrect tokens: %tokens',
         array('%tokens' => implode(', ', $tokens_missing)));
       form_set_error('set_titles][title_format', $msg);
     }
-    
+
   }
   else {
     $msg = t('You should use at least one token in your title format or the title for all %type pages will be the same.',
@@ -217,14 +238,23 @@ function tripal_entities_tripal_bundle_form_validate($form, $form_state) {
  * Submit: Tripal content type edit form.
  */
 function tripal_entities_tripal_bundle_form_submit($form, &$form_state) {
-  
+
   if ($form_state['triggering_element']['#value'] == 'Save Content Type') {
+    $bundle_entity = $form_state['build_info']['args'][0];
+
+    // Save the label.
+    $bundle_entity->label = $form_state['values']['label'];
+    $bundle_entity->save();
+
+    // Save the description.
+    tripal_bundle_save_variable('description', $bundle_entity->id, $form_state['values']['description']);
+
     // Save the page title format.
     tripal_save_title_format(
-      $form_state['build_info']['args'][0], 
+      $bundle_entity,
       $form_state['values']['set_titles']['title_format']
     );
-    
+
     $form_state['redirect'] = 'admin/structure/bio-data';
     drupal_set_message(t('Successfully saved %type content type.', array('%type' => $form_state['build_info']['args'][0]->label)));
   }

+ 0 - 1
tripal_entities/includes/TripalEntity.inc

@@ -5,7 +5,6 @@
 class TripalEntity extends Entity {
   public function __construct($values = array(), $entity_type) {
     parent::__construct($values, $entity_type);
-
   }
 
   protected function defaultLabel() {

+ 6 - 9
tripal_entities/includes/TripalEntityController.inc

@@ -9,6 +9,7 @@ class TripalEntityController extends EntityAPIController {
 
   public function __construct($entityType) {
     parent::__construct($entityType);
+
   }
 
   /**
@@ -25,6 +26,7 @@ class TripalEntityController extends EntityAPIController {
    *   An object with all default fields initialized.
    */
   public function create(array $values = array()) {
+
     // Add some items to the values array passed to the constructor
     global $user;
     $values['uid'] = $user->uid;
@@ -36,15 +38,9 @@ class TripalEntityController extends EntityAPIController {
     $bundle = $values['bundle'];
     $matches = array();
     if (preg_match('/bio-data_(.*)/', $bundle, $matches)) {
-      $cvterm_id = $matches[1];
+      $term_id = $matches[1];
       $values['type'] = 'TripalEntity';
-
-      // Get the CVterm.
-      $match = array('cvterm_id' => $cvterm_id);
-      $cvterm = tripal_get_cvterm($match);
-      if ($cvterm) {
-        $values['cvterm_id'] = $cvterm->cvterm_id;
-      }
+      $values['term_id'] = $term_id;
     }
 
     return parent::create($values);
@@ -102,6 +98,7 @@ class TripalEntityController extends EntityAPIController {
           if (isset($entity->{$field})) {
 
             // Render the value from the field.
+            // @TODO: Handle the case where thefield is empty... currently returns error.
             $field_value = field_get_items('TripalEntity', $entity, $field);
             $field_render_arr = field_view_value('TripalEntity', $entity, $field, $field_value[0]);
             $value = render($field_render_arr);
@@ -147,7 +144,7 @@ class TripalEntityController extends EntityAPIController {
 
       // Write out the entity record.
       $record = array(
-        'cvterm_id' => $entity->cvterm_id,
+        'term_id'   => $entity->term_id,
         'type'      => $entity->type,
         'bundle'    => $entity->bundle,
         'title'     => $entity->title,

+ 38 - 19
tripal_entities/includes/TripalEntityUIController.inc

@@ -32,29 +32,30 @@ class TripalEntityUIController extends EntityDefaultUIController {
       'page callback' => 'tripal_entities_add_page',
       'file' =>  'includes/tripal_entities.entity_form.inc',
       'file path' => drupal_get_path('module', 'tripal_entities'),
-      'access callback'  => 'tripal_entities_entity_access',
-      'access arguments' => array('edit'),
+      'access arguments' => array('administer tripal data'),
     );
 
     // Add a menu item for creating each bundle
     $bundles = array_keys($this->entityInfo['bundles']);
-    foreach ($bundles as $bundle) {
+    foreach ($bundles as $bundle_name) {
       $matches = array();
-      preg_match('/^bio-data_(.*?)$/', $bundle, $matches);
-      $cvterm_id = $matches[1];
-      $cvterm = tripal_get_cvterm(array('cvterm_id' => $cvterm_id));
-
-      // Set a custom page for adding new tripal data entities.
-      $items['bio-data/add/' . $cvterm_id] = array(
-        'title' => ucfirst($cvterm->name),
-        'description' => 'A ' . $cvterm->name . ' record.',
-        'page callback'  => 'drupal_get_form',
-        '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'),
-      );
+      if (preg_match('/^bio-data_(.*?)$/', $bundle_name, $matches)) {
+        $bundle = tripal_load_bundle_entity($bundle_name);
+        // Get the term for this bundle
+        $term = entity_load('TripalTerm', array('id' => $matches[1]));
+        $term = reset($term);
+        // Set a custom page for adding new tripal data entities.
+        $items['bio-data/add/' . $term->id] = array(
+          'title' => ucfirst($bundle->label),
+          'description' => tripal_get_bundle_variable('description', $bundle->id, $term->definition),
+          'page callback'  => 'drupal_get_form',
+          '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'),
+        );
+      }
     }
 
     // Link for viewing a tripal data type.
@@ -115,4 +116,22 @@ class TripalEntityUIController extends EntityDefaultUIController {
 function tripal_entity_manage_fields($entity) {
   drupal_goto('admin/structure/bio-data/manage/' . $entity->bundle . '/fields');
   return '';
-}
+}
+
+/**
+ * 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_entities_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;
+ }

+ 28 - 0
tripal_entities/includes/TripalTerm.inc

@@ -6,6 +6,29 @@ class TripalTerm extends Entity {
   public function __construct($values = array()) {
     parent::__construct($values, 'TripalTerm');
 
+    // Get the vocabulary for this term
+    $vocab = entity_load('TripalVocab', array('id' => $this->vocab_id));
+    $vocab = reset($vocab);
+
+    // Get the term description from the storage backend
+    $this->definition = '';
+
+    // TODO: we need some sort of administrative interface that lets the user
+    // switch to the desired vocabulary type. For now, we'll just use the
+    // first one in the list.
+    $stores = module_invoke_all('vocab_storage_info');
+    if (is_array($stores) and count($stores) > 0) {
+      $keys = array_keys($stores);
+      $module = $stores[$keys[0]]['module'];
+      $function = $module . '_vocab_get_term';
+      if (function_exists($function)) {
+        $term_details = $function($vocab->namespace, $this->term_id);
+        $this->details = $term_details;
+        if ($term_details and $term_details['definition']) {
+          $this->definition = $term_details['definition'];
+        }
+      }
+    }
   }
 
   protected function defaultLabel() {
@@ -17,4 +40,9 @@ class TripalTerm extends Entity {
     return array('path' => '/vocabulary/' . $vocab . '/term/' . $this->id);
   }
 
+  public function getDefinition() {
+
+    return '';
+  }
+
 }

+ 9 - 6
tripal_entities/includes/tripal_entities.admin.inc

@@ -35,7 +35,7 @@ function tripal_entities_content_view() {
 function tripal_entities_content_overview_form($form, &$form_state) {
 
   // Set the title to be informative (defaults to content for some reason).
-  drupal_set_title('Biological Data');
+  drupal_set_title('Tripal Content');
 
   // Retrieve a pages list of all tripal entitles (ie: biological data).
   // This will return the 25 most recently created entities.
@@ -51,8 +51,11 @@ function tripal_entities_content_overview_form($form, &$form_state) {
   // For each entity retrieved add a row to the data listing.
   while ($entity = $entities->fetchObject()) {
 
-    // Retrieve details about the term this entity is based on.
-    $cvterm = tripal_get_cvterm(array('cvterm_id' => $entity->cvterm_id));
+    // Get the term
+    $term = entity_load('TripalTerm', array('id' => $entity->term_id));
+    $term = reset($term);
+    $vocab = entity_load('TripalVocab', array('id' => $term->vocab_id));
+    $vocab = reset($vocab);
 
     // Retrieve details about the user who created this data.
     $author = user_load($entity->uid);
@@ -60,8 +63,8 @@ function tripal_entities_content_overview_form($form, &$form_state) {
     // Add information to the table.
     $rows[] = array(
       l($entity->title, 'bio-data/' . $entity->id),
-      $cvterm->cv_id->name . ' (' . $cvterm->dbxref_id->db_id->name . ')',
-      $cvterm->name,
+      $vocab->namespace,
+      $term->name,
       l($author->name, 'user/' . $entity->uid),
       $entity->status == 1 ? 'published' : 'unpublished',
       format_date($entity->changed, 'short'),
@@ -75,7 +78,7 @@ function tripal_entities_content_overview_form($form, &$form_state) {
   if (empty($rows)) {
     $rows[] = array(
       array(
-        'data' => t('No biological data available.'),
+        'data' => t('No Tripal content available.'),
         'colspan' => 7
       )
     );

+ 5 - 5
tripal_entities/includes/tripal_entities.entity_form.inc

@@ -43,7 +43,7 @@ function theme_tripal_entities_add_list($variables) {
   }
   else {
     $output = tripal_set_message(
-      t('This page is for adding biological data 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".'),
+      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)
     );
@@ -58,9 +58,9 @@ function theme_tripal_entities_add_list($variables) {
 /**
  *
  */
-function tripal_entities_entity_form($form, &$form_state, $cvterm_id = '', $entity = NULL) {
+function tripal_entities_entity_form($form, &$form_state, $term_id = '', $entity = NULL) {
 
-  $bundle_id = 'bio-data_' . $cvterm_id;
+  $bundle_name = 'bio-data_' . $term_id;
 
   // Add a vertical tabs element
   $form['entity_form_vtabs'] = array(
@@ -70,7 +70,7 @@ function tripal_entities_entity_form($form, &$form_state, $cvterm_id = '', $enti
 
   // If the entity doesn't exist then create one.
   if (!$entity) {
-    $entity = entity_get_controller('TripalEntity')->create(array('bundle' => $bundle_id));
+    $entity = entity_get_controller('TripalEntity')->create(array('bundle' => $bundle_name));
     field_attach_form('TripalEntity', $entity, $form, $form_state);
 
     $form['add_button'] = array(
@@ -100,7 +100,7 @@ function tripal_entities_entity_form($form, &$form_state, $cvterm_id = '', $enti
   // the Entity API to work. It must have a key of the entity name.
   $form_state['TripalEntity'] = $entity;
 
-  $form['#prefix'] = "<div id='$bundle_id-entity-form'>";
+  $form['#prefix'] = "<div id='$bundle_name-entity-form'>";
   $form['#suffix'] = "</div>";
   return $form;
 

+ 11 - 0
tripal_entities/tripal_entities.install

@@ -4,6 +4,17 @@
  * Install for a tripal data entity - creates the base table for our entity.
  */
 
+/**
+ * Implements hook_install().
+ */
+function tripal_entities_install() {
+
+  // Add tripal bundle variables needed for storing additional settings for Tripal Bundles.
+  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.');
+  
+}
 
 /**
  * Implements hook_schema().

+ 14 - 7
tripal_entities/tripal_entities.module

@@ -156,7 +156,13 @@ function tripal_entities_permission() {
 
   return $permissions;
 }
-
+/**
+ * Checks access permissions for a given entity.
+ */
+function tripal_entities_entity_access($entity) {
+  // TODO: need to implement this function.
+  return TRUE;
+}
 /**
  * Implements hook_theme().
  */
@@ -426,16 +432,17 @@ function tripal_entities_entity_info_alter(&$entity_info){
       ->execute();
 
     while ($bundle = $bundles->fetchObject()) {
-      $bundle_id = $bundle->bundle;
-      $cvterm_id = preg_replace('/bio-data_/', '', $bundle_id);
-      $cvterm = tripal_get_cvterm(array('cvterm_id' => $cvterm_id));
-      $label = preg_replace('/_/', ' ', ucwords($cvterm->name));
+      $bundle_name = $bundle->bundle;
+      $term_id = preg_replace('/bio-data_/', '', $bundle_name);
+      $term = entity_load('TripalTerm', array('id' => $term_id));
+      $term = reset($term);
+      $label = preg_replace('/_/', ' ', ucwords($term->name));
 
-      $entity_info['TripalEntity']['bundles'][$bundle_id] = array (
+      $entity_info['TripalEntity']['bundles'][$bundle_name] = array (
         'label' => $label,
         'admin' => array (
           'path' => 'admin/structure/bio-data/manage/%tripal_bundle',
-          'real path' => 'admin/structure/bio-data/manage/' . $bundle_id,
+          'real path' => 'admin/structure/bio-data/manage/' . $bundle_name,
           'bundle argument' => 4,
           'access arguments' => array (
             'administer tripal data types'