Explorar o código

Fixed bug in pub module. Drupal only allows a node title to be 255 characters but the Chado pub.title field can be longer. Had to adjust for that as the publication title is the Drupal node title

spficklin %!s(int64=12) %!d(string=hai) anos
pai
achega
35ce1e2214

+ 11 - 4
tripal_pub/includes/pub_form.inc

@@ -11,8 +11,8 @@ function chado_pub_form($node, $form_state) {
   
   $pub = $node->pub;  
   $pub_id = $pub->pub_id;
-  
-  $d_title        = $form_state['values']['title']        ? $form_state['values']['title']       : $node->title;
+    
+  $d_title        = $form_state['values']['pubtitle']     ? $form_state['values']['pubtitle']    : $pub->title;
   $d_uniquename   = $form_state['values']['uniquename']   ? $form_state['values']['uniquename']  : $pub->uniquename;
   $d_type_id      = $form_state['values']['type_id']      ? $form_state['values']['type_id']     : $pub->type_id->cvterm_id;
   $d_volume       = $form_state['values']['volume']       ? $form_state['values']['volume']      : $pub->volume;
@@ -94,7 +94,14 @@ function chado_pub_form($node, $form_state) {
     '#value' => $pub_id,
   );
   
+  // a drupal title can only be 255 characters, but the Chado title can be much longer.
+  // we use the publication title as the drupal title, but we'll need to truncate it.
   $form['title'] = array(
+    '#type' => 'hidden',
+    '#value' => substr($d_title, 0, 255),
+  );
+  
+  $form['pubtitle'] = array(
     '#type' => 'textarea',
     '#title' => t('Publication Title'),
     '#default_value' => $d_title,
@@ -168,7 +175,7 @@ function chado_pub_form($node, $form_state) {
 function chado_pub_validate($node, &$form) {
   
   // get the submitted values
-  $title        = trim($node->title);
+  $title        = trim($node->pubtitle);
   $uniquename   = trim($node->uniquename);
   $type_id      = trim($node->type_id);
   $volume       = trim($node->volume);
@@ -592,7 +599,7 @@ function theme_chado_pub_node_form($form) {
   $properties_table = tripal_pub_theme_node_form_properties($form);
   
   $markup  = drupal_render($form['pub_id']);
-  $markup .= drupal_render($form['title']);
+  $markup .= drupal_render($form['pubtitle']);
   $markup .= drupal_render($form['type_id']);
   $markup .= drupal_render($form['series_name']);
   $markup .= drupal_render($form['pyear']);

+ 2 - 1
tripal_pub/includes/pub_sync.inc

@@ -72,7 +72,8 @@ function tripal_pub_sync_pub($pub) {
   $new_node->pub_id      = $pub->pub_id;
   $new_node->type        = 'chado_pub';
   $new_node->uid         = $user->uid;
-  $new_node->title       = $pub->title;
+  $new_node->title       = substr($pub->title, 0 ,255); // node titles can't be longer than 255 characters
+  $new_node->pubtitle    = $pub->title;
   $new_node->pyear       = $pub->pyear;
   $new_node->uniquename  = $pub->uniquename;
   $new_node->type_id     = $pub->type_id;

+ 6 - 6
tripal_pub/tripal_pub.module

@@ -391,7 +391,7 @@ function chado_pub_insert($node) {
     
     // insert the pub record
     $values = array(
-      'title'       => trim($node->title),
+      'title'       => trim($node->pubtitle),
       'series_name' => trim($node->series_name),
       'type_id'     => trim($node->type_id),
       'pyear'       => trim($node->pyear),
@@ -574,7 +574,7 @@ function chado_pub_update($node) {
     'pub_id' => $pub_id,
   );
   $values = array(
-    'title'       => trim($node->title),
+    'title'       => trim($node->pubtitle),
     'type_id'     => trim($node->type_id),
     'pyear'       => trim($node->pyear),
     'is_obsolete' => $node->is_obsolete ? 'true' : 'false', 
@@ -639,15 +639,15 @@ function chado_pub_load($node) {
 
   $values = array('pub_id' => $pub_id);
   $pub = tripal_core_generate_chado_var('pub', $values); 
-  
+    
   // expand the 'text' fields as those aren't included by default
   // and they really shouldn't be so large to cause problems
-  if (is_array($pub)) {
+  if (is_array($pub) or is_object($pub)) {
     $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
     $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.volumetitle');  
-    $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.uniquename');;
+    $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.uniquename');
   }
-  
+    
   // set the URL path
   $path = "pub/$pub_id";