瀏覽代碼

Chado Node API -URLs: implemented for organism nodes

Lacey Sanderson 10 年之前
父節點
當前提交
2d2622242f

+ 16 - 0
tripal_organism/includes/tripal_organism.admin.inc

@@ -67,6 +67,22 @@ function tripal_organism_admin() {
   // This sub-form handles it's own validation & submit
   chado_add_admin_form_set_title($form, $form_state, $details);
 
+  // URL ALIAS
+  $details = array(
+    'module' => 'tripal_organism',
+    'content_type' => 'chado_organism',
+    'options' => array(
+      '/organism/[organism.organism_id]' => 'Organism ID',
+      '/organism/[organism.abbreviation]' => 'The abbreviation for the organism',
+      '/organism/[organism.common_name]' => 'The common name of the organism',
+      '/organism/[organism.genus]/[organism.species]' => 'Unique Contraint: the scientific name.'
+    ),
+  );
+
+  // This call adds the configuration form to your current form
+  // This sub-form handles it's own validation & submit
+  chado_add_admin_form_set_url($form, $form_state, $details);
+
   return system_settings_form($form);
 }
 

+ 17 - 7
tripal_organism/includes/tripal_organism.chado_node.inc

@@ -587,6 +587,9 @@ function tripal_organism_node_insert($node) {
       // Now get the title
       $node->title = chado_get_node_title($node);
 
+      // Now use the API to set the path.
+      chado_set_node_url($node);
+
       break;
   }
 }
@@ -602,15 +605,12 @@ function tripal_organism_node_update($node) {
   switch ($node->type) {
     case 'chado_organism':
       
-      // find the organism and add in the details
-      $organism_id = chado_get_id_from_nid('organism', $node->nid);
-      $values = array('organism_id' => $organism_id);
-      $organism = chado_generate_var('organism', $values);
-      $node->organism = $organism;
-
-      // Now get the title
+      // Now get the title.
       $node->title = chado_get_node_title($node);
 
+      // Now use the API to set the path.
+      chado_set_node_url($node);
+
       break;
   }
 }
@@ -624,3 +624,13 @@ function tripal_organism_node_update($node) {
 function chado_organism_chado_node_default_title_format() {
   return '[organism.genus] [organism.species]';
 }
+
+/**
+ * Implements hook_chado_node_default_url_format().
+ *
+ * Designates a default URL format for organism nodes.
+ */
+function chado_organism_chado_node_default_url_format() {
+  return '/organism/[organism.genus]/[organism.species]';
+}
+