Browse Source

Chado Node API -URLs: implemented for contact nodes

Lacey Sanderson 10 years ago
parent
commit
945b0425b4

+ 14 - 0
tripal_contact/includes/tripal_contact.admin.inc

@@ -69,6 +69,20 @@ function tripal_contact_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_contact',
+    'content_type' => 'chado_contact',
+    'options' => array(
+      '/contact/[contact.contact_id]' => 'Contact ID',
+      '/contact/[contact.name]' => 'Unique Contraint: The name of the contact'
+    ),
+  );
+
+  // 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 - 10
tripal_contact/includes/tripal_contact.chado_node.inc

@@ -669,6 +669,9 @@ function tripal_contact_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;
   }
 }
@@ -684,17 +687,12 @@ function tripal_contact_node_update($node) {
   switch ($node->type) {
     case 'chado_contact':
 
-      // find the contact and add in the details
-      $contact_id = chado_get_id_from_nid('contact', $node->nid);
-
-      // get the contact
-      $values = array('contact_id' => $contact_id);
-      $contact = chado_generate_var('contact', $values);
-      $node->contact = $contact;
-
-      // Now get the title
+      // Set the title
       $node->title = chado_get_node_title($node);
 
+      // Now use the API to set the path.
+      chado_set_node_url($node);
+
       break;
   }
 }
@@ -709,6 +707,15 @@ function chado_contact_chado_node_default_title_format() {
   return '[contact.name]';
 }
 
+/**
+ * Implements hook_chado_node_default_url_format().
+ *
+ * Designates a default URL format for contact nodes.
+ */
+function chado_contact_chado_node_default_url_format() {
+  return '/contact/[contact.name]';
+}
+
 /**
  * Implements [content_type]_chado_node_sync_select_query().
  *
@@ -721,4 +728,4 @@ function chado_contact_chado_node_sync_select_query($query) {
   $query['where_args']['title'][':contact_name_null2'] = 'NULL';
 
   return $query;
-}
+}