Browse Source

Fixed the publication field. It wasn't saving

Stephen Ficklin 7 years ago
parent
commit
5ee2c2826c

+ 2 - 2
tripal/includes/TripalEntityUIController.inc

@@ -512,8 +512,8 @@ function tripal_entity_form_ajax_callback($form, $form_state) {
 
    // If the user is cancelling or deleting the entity then don't validate.
    if (array_key_exists('clicked_button', $form_state) and
-       $form_state['clicked_button']['#name'] =='cancel_data' or
-       $form_state['clicked_button']['#name'] =='delete_data') {
+       ($form_state['clicked_button']['#name'] == 'cancel_data' or
+        $form_state['clicked_button']['#name'] == 'delete_data')) {
      return;
    }
    // For adds and updates, perform validation.

+ 0 - 4
tripal/includes/TripalFields/TripalField.inc

@@ -56,10 +56,6 @@ class TripalField {
     // is convenient for speed.  Fields that are slow should for loading
     // should ahve auto_attach set to FALSE so tha their values can be
     // attached asyncronously.
-    'auto_attach' => TRUE,
-    // Set to TRUE to turn on paging capabilities.  Implementations of
-    // a new field should honor this setting when loading results and
-    // when formatting for dipslay.
   );
 
   // The default widget for this field.

+ 9 - 0
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship.inc

@@ -35,12 +35,21 @@ class sbo__relationship extends ChadoField {
     // type. This will create form elements when editing the field instance
     // to allow the site admin to change the term settings above.
     'term_fixed' => FALSE,
+    // Inidates if this field should be automatically attached to display
+    // or web services or if this field should be loaded separately. This
+    // is convenient for speed.  Fields that are slow should for loading
+    // should ahve auto_attach set to FALSE so tha their values can be
+    // attached asyncronously.
+    'auto_attach' => FALSE,
+    // Settings to help the site admin control how relationship types and
+    // valid subject/objects can be selected by the user.
     'relationships' => array(
       'option1_vocabs' => '',
       'option2_vocab' => '',
       'option2_parent' => '',
       'relationship_types' => '',
     ),
+    // The number of items to show on a page.
     'items_per_page' => 10,
   );
 

+ 10 - 9
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_formatter.inc

@@ -115,7 +115,12 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
     $pager = $this->ajaxifyPager($pager, $entity);
     $page_items = array_chunk($rows, $items_per_page);
 
-    $content = 'There are ' . count($items) . ' relationships';
+    if (count($items) == 1) {
+      $content = 'There is ' . count($items) . ' relationship.';
+    }
+    else {
+      $content = 'There are ' . count($items) . ' relationships.';
+    }
     $content .= theme_table(array(
       'header' => $headers,
       'rows' => $page_items[$current_page],
@@ -128,14 +133,10 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
       'empty' => $settings['empty'],
     ));
 
-    // Once we have our table array structure defined, we call Drupal's theme_table()
-    // function to generate the table.
-    if (count($items) > 0) {
-      $element[0] = array(
-        '#type' => 'markup',
-        '#markup' => $content . $pager,
-      );
-    }
+    $element[0] = array(
+      '#type' => 'markup',
+      '#markup' => $content . $pager,
+    );
   }
 }
 

+ 6 - 2
tripal_chado/includes/TripalFields/schema__publication/schema__publication_formatter.inc

@@ -22,8 +22,12 @@ class schema__publication_formatter extends ChadoFieldFormatter {
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
     $list_items = array();
     $chado_table = $this->instance['settings']['chado_table'];
+
     foreach ($items as $delta => $item) {
 
+      if (empty($item['value'])) {
+        continue;
+      }
       $title = isset($item['value']['TPUB:0000039']) ? $item['value']['TPUB:0000039'] : '';
       $citation = isset($item['value']['TPUB:0000003']) ? $item['value']['TPUB:0000003'] : '';
       $entity = array_key_exists('entity', $item['value']) ? $item['value']['entity'] : '';
@@ -39,10 +43,10 @@ class schema__publication_formatter extends ChadoFieldFormatter {
       $list_items[] = $citation;
     }
 
+    $list = '';
     krsort($list_items, SORT_NUMERIC);
-
     if (count($list_items) == 0) {
-      $list = 'There are no publications.';
+      $list = 'There are no publications associated with this record.';
     }
     if (count($list_items) == 1) {
       $list = $list_items[0];

+ 2 - 4
tripal_chado/includes/TripalFields/schema__publication/schema__publication_widget.inc

@@ -25,15 +25,13 @@ class schema__publication_widget extends ChadoFieldWidget {
     $fkey = $fkeys[0];
 
     // Get the field defaults.
-    $record_id = '';
-    $fkey_value = array_key_exists('#entity', $element) and $element['#entity'] ? $element['#entity']->chado_record_id : NULL;
+    $fkey_value = (array_key_exists('#entity', $element) and is_object($element['#entity'])) ? $element['#entity']->chado_record_id : NULL;
     $pub_id = '';
     $uname = '';
 
     // If the field already has a value then it will come through the $items
     // array.  This happens when editing an existing record.
     if (count($items) > 0 and array_key_exists($delta, $items)) {
-      $record_id = tripal_get_field_item_keyval($items, $delta, 'chado-' . $table_name . '__' . $pkey, $record_id);
       $pub_id = tripal_get_field_item_keyval($items, $delta, 'chado-' . $table_name . '__pub_id', $pub_id);
       $uname = tripal_get_field_item_keyval($items, $delta, 'uniquename', $uname);
     }
@@ -52,7 +50,7 @@ class schema__publication_widget extends ChadoFieldWidget {
 
     $widget['chado-' . $table_name . '__' . $pkey] = array(
       '#type' => 'value',
-      '#default_value' => $record_id,
+      '#default_value' => '',
     );
     $widget['chado-' . $table_name . '__' . $fkey] = array(
       '#type' => 'value',

+ 1 - 0
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -42,6 +42,7 @@ function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
 
   // Convert the fields into a key/value list of fields and their values.
   $field_vals = tripal_chado_field_storage_write_merge_fields($fields, $entity_type, $entity);
+dpm($field_vals);
 
   // First, write the record for the base table.  If we have a record id then
   // this is an update and we need to set the primary key.  If not, then this