Browse Source

Chado Node API: Replaces feature title functionality with the new API including handling the legacy options

Lacey Sanderson 11 years ago
parent
commit
a80007b178

+ 16 - 3
tripal_core/api/tripal_core.chado_nodes.title_and_path.inc

@@ -13,6 +13,7 @@
     // for your node type then you need to add the configuration form for this functionality.
     $details = array(
       'module' => 'tripal_example',       // the name of the MODULE implementing the content type
+      'content_type' => 'chado_example'   // the name of the content type
         // An array of options to use under "Page Titles"
         // the key should be the token and the value should be the human-readable option
       'options' => array(
@@ -158,7 +159,7 @@ function chado_add_admin_form_set_title(&$form, &$form_state, $details) {
   $details['custom_tokens'] = (isset($details['custom_tokens'])) ? $details['custom_tokens'] : array();
   $details['content_type'] = (isset($details['content_type'])) ? $details['content_type'] : $details['module'];
   $details['default_option'] = (isset($details['default_option'])) ? $details['default_option'] : FALSE;
-  $details['default_option'] = ($details['default_option'] === FALSE) ? chado_node_get_token_format('title', $node_info[ $details['module'] ]['base']) : $details['default_option'];
+  $details['default_option'] = ($details['default_option'] === FALSE) ? chado_node_get_token_format('title', $node_info[ $details['content_type'] ]['base']) : $details['default_option'];
   $details['default_option'] = ($details['default_option'] === FALSE) ? $details['unique_option'] : $details['default_option'];
 
 
@@ -294,7 +295,19 @@ function chado_add_admin_form_set_title_form_submit($form, $form_state) {
  */
 function chado_node_get_legacy_title_default($content_type) {
   if ($content_type == 'chado_feature') {
-
+    $legacy_option = variable_get('chado_feature_title', 'unique_constraint');
+    switch ($legacy_option) {
+      case 'feature_unique_name':
+        $default_title_format = '[feature.uniquename]';
+        break;
+      case 'feature_name':
+        $default_title_format = '[feature.name]';
+        break;
+      case 'unique_constraint':
+        $default_title_format = '[feature.name], [feature.uniquename] ([feature.type_id>cvterm.name]) [feature.organism_id>organism.genus] [feature.organism_id>organism.species]';
+        break;
+    }
+    return $default_title_format;
   }
   elseif ($content_type == 'chado_stock') {
     $legacy_option = variable_get('chado_stock_title', 'unique_constraint');
@@ -379,7 +392,7 @@ function chado_node_add_token_format($application, $content_type, $format, $toke
  * @return
  *   A string specifying the format
  */
-function chado_node_get_token_format($application, $content_type, $options) {
+function chado_node_get_token_format($application, $content_type, $options = array()) {
 
   $format_record = db_select('tripal_token_formats','t')
     ->fields('t')

+ 21 - 0
tripal_feature/includes/tripal_feature.admin.inc

@@ -47,6 +47,26 @@ function tripal_feature_admin_feature_view() {
 function tripal_feature_admin() {
 
   // FEATURE PAGE TITLES
+  // Using the Chado Node: Title & Path API
+  $details = array(
+    'module' => 'tripal_feature',
+    'content_type' => 'chado_feature',
+      // An array of options to use under "Page Titles"
+      // the key should be the token and the value should be the human-readable option
+    'options' => array(
+      '[feature.name]' => 'Feature Name Only',
+      '[feature.uniquename]' => 'Feature Unique Name Only',
+        // there should always be one options matching the unique constraint.
+      '[feature.name], [feature.uniquename] ([feature.type_id>cvterm.name]) [feature.organism_id>organism.genus] [feature.organism_id>organism.species]' => 'Unique Contraint: Includes the name, uniquename, type and scientific name'
+    ),
+    // the token indicating the unique constraint in the options array
+    'unique_option' => '[feature.name], [feature.uniquename] ([feature.type_id>cvterm.name]) [feature.organism_id>organism.genus] [feature.organism_id>organism.species]'
+  );
+  // This call adds the configuration form to your current form
+  // This sub-form handles it's own validation & submit
+  chado_add_admin_form_set_title($form, $form_state, $details);
+    
+/**
   $form['title'] = array(
     '#type' => 'fieldset',
     '#title' => t('Feature Page Titles'),
@@ -77,6 +97,7 @@ function tripal_feature_admin() {
     '#options'       => $options,
     '#default_value' => variable_get('chado_feature_title', 'unique_constraint'),
   );
+  */
     
   // FEATURE URL PATHS
   $form['url'] = array(

+ 10 - 22
tripal_feature/includes/tripal_feature.chado_node.inc

@@ -712,28 +712,8 @@ function chado_feature_load($nodes) {
     $feature = chado_generate_var('feature', $values);
     $nodes[$nid]->feature = $feature;
 
-    // by default, the titles are saved using the unique constraint.  We will
-    // keep it the same, but remove the duplicate name if the unique name and name
-    // are identical. This doesn't change the title saved in the database, just what is shown
-    // to the user on the page
-    $title_type = variable_get('chado_feature_title', 'unique_constraint');
-    if ($title_type == 'unique_constraint') {
-      if (strcmp($feature->name, $feature->uniquename)==0) {
-        $node->title = $feature->name . " (" . $feature->type_id->name . ") " . $feature->organism_id->genus . " " . $feature->organism_id->species ;
-      }
-      // in previous version of Tripal, the feature title was simply the unique name.
-      // so, we recreate the title just to be sure all of our feature pages are consistent
-      else {
-        $node->title = $feature->name . ", " . $feature->uniquename . " (" . $feature->type_id->name . ") " . $feature->organism_id->genus . " " . $feature->organism_id->species ;
-      }
-    }
-    // set the title to be the feature name or uniquename as configured
-    if ($title_type == 'feature_name') {
-      $node->title = $feature->name;
-    }
-    if ($title_type == 'feature_unique_name') {
-      $node->title = $feature->uniquename;
-    }
+    // Now get the title
+    $node->title = chado_get_node_title($node);
   }
 }
 
@@ -805,6 +785,10 @@ function tripal_feature_node_insert($node) {
       $url_alias = tripal_feature_get_feature_url($node);
       $path_alias = array("source" => "node/$node->nid", "alias" => $url_alias);
       path_save($path_alias);
+
+      // Now get the title
+      $node->title = chado_get_node_title($node);
+      
       break;
   }
 }
@@ -827,6 +811,10 @@ function tripal_feature_node_update($node) {
       $url_alias = tripal_feature_get_feature_url($node);
       $path_alias = array("source" => "node/$node->nid", "alias" => $url_alias);
       path_save($path_alias);
+
+      // Now get the title
+      $node->title = chado_get_node_title($node);
+      
       break;
   }
 }