Browse Source

Fixed bugs related to setting titles.

Lacey Sanderson 9 years ago
parent
commit
a748fa6fdb

+ 4 - 17
tripal_chado/includes/tripal_chado.entity.inc

@@ -3,21 +3,12 @@
 /**
  * Implements hook_entity_presave().
  */
-function tripal_chado_entity_presave($entity, $type) {
-
-}
+function tripal_chado_entity_presave($entity, $type) { }
 
 /**
  * Implements hook_entity_postsave().
  */
-function tripal_chado_entity_postsave($entity, $type) {
-
-  // Set the title for this entity.
-  // This needs to be done post save because it uses the saved data and a format.
-  $ec = new TripalEntityController($entity->type);
-  $ec->setTitle($entity);
-
-}
+function tripal_chado_entity_postsave($entity, $type) { }
 
 /**
  *
@@ -34,17 +25,13 @@ function tripal_chado_entity_load($entities, $type) {
  *
  * Implements hook_entity_insert().
  */
-function tripal_entities_entity_insert($entity, $type) {
-
-}
+function tripal_chado_entity_insert($entity, $type) { }
 
 /**
  *
  * Implements hook_entity_update().
  */
-function tripal_chado_entity_update($entity, $type) {
-
-}
+function tripal_chado_entity_update($entity, $type) { }
 
 /**
  *

+ 11 - 7
tripal_entities/includes/TripalBundleUIController.inc

@@ -74,8 +74,10 @@ 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));
+  $term = NULL;
+  $vocab = NULL;
+  if (preg_match('/bio-data_(\d+)/', $entity_type->bundle, $matches)) {
+    $term = entity_load('TripalTerm', array('id' => $matches[1]));
     $term = reset($term);
     $vocab = entity_load('TripalVocab', array('id' => $term->vocab_id));
     $vocab = reset($vocab);
@@ -95,7 +97,7 @@ function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType
     ),
   );
 
-    if ($term) {
+  if ($term) {
     $form['term'] = array(
       '#type' => 'markup',
       '#markup' => theme('table', array(
@@ -124,10 +126,12 @@ function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType
     '#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;
+  if ($term) {
+    $form['description']['#default_value'] = tripal_get_bundle_variable('description', $entity_type->id, $term->definition);
+  }
+  else {
+    $form['description']['#default_value'] = tripal_get_bundle_variable('description', $entity_type->id, '');
   }
 
   $form['additional_settings'] = array(
@@ -247,7 +251,7 @@ function tripal_entities_tripal_bundle_form_submit($form, &$form_state) {
     $bundle_entity->save();
 
     // Save the description.
-    tripal_bundle_save_variable('description', $bundle_entity->id, $form_state['values']['description']);
+    tripal_set_bundle_variable('description', $bundle_entity->id, $form_state['values']['description']);
 
     // Save the page title format.
     tripal_save_title_format(

+ 5 - 1
tripal_entities/includes/TripalEntityController.inc

@@ -88,7 +88,7 @@ class TripalEntityController extends EntityAPIController {
       $title = tripal_get_title_format($bundle_entity);
 
       // Determine which tokens were used in the format string
-      if (preg_match_all('/\[\w+\.\w+\]/', $title, $matches)) {
+      if (preg_match_all('/\[\w+\]/', $title, $matches)) {
         $used_tokens = $matches[0];
 
         foreach($used_tokens as $token) {
@@ -170,6 +170,10 @@ class TripalEntityController extends EntityAPIController {
       else {
         field_attach_update('TripalEntity', $entity);
       }
+      
+      // Set the title for this entity.
+      $ec = new TripalEntityController($entity->type);
+      $ec->setTitle($entity);
 
       // Invoke either hook_entity_update() or hook_entity_insert().
       module_invoke_all('entity_postsave', $entity, $entity->type);