Browse Source

Fixed problems related to issue #433

Stephen Ficklin 6 years ago
parent
commit
554d5f3637

+ 4 - 2
tripal/api/tripal.terms.api.inc

@@ -689,7 +689,9 @@ function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
     // TODO: this should not call the chado functions because we're in the
     // tripal module.
     $terms = chado_generate_var('cvterm', $match, array('return_array' => TRUE));
-    $terms = chado_expand_var($terms, 'field', 'cvterm.definition');
+    if ($terms) {
+      $terms = chado_expand_var($terms, 'field', 'cvterm.definition');
+    }
     $num_terms = 0;
     $selected_term = '';  
 
@@ -712,7 +714,7 @@ function tripal_get_term_lookup_form(&$form, &$form_state, $default_name = '',
         '#attributes' => $attrs,
         '#description' => '<b>Vocabulary:</b> ' . $term->cv_id->name . ' (' . $term->dbxref_id->db_id->name . ') ' . $term->cv_id->definition .
         '<br><b>Term: </b> ' . $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession . '.  ' .
-        '<br><b>Definition:</b>  ' . $term->definition,
+        '<br><b>Definition:</b>  ' . property_exists($term, 'definition') ? $term->definition : '',
         '#ajax' => array(
           'callback' => "tripal_get_term_lookup_form_ajax_callback",
           'wrapper' => $ajax_wrapper_id,

+ 3 - 2
tripal_chado/api/tripal_chado.variables.api.inc

@@ -621,10 +621,11 @@ function chado_expand_var($object, $type, $to_expand, $table_options = array())
 
   // Make sure we have a value.
   if (!$object) {
+    $trace = (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS));
     tripal_report_error('tripal_chado',
       TRIPAL_ERROR,
-      'Cannot pass non array as argument, $object, to chado_expand_var function.',
-      array());
+      'Missing $object argument to the chado_expand_var function from %caller (line: %line)',
+      array('%caller' => $trace[1]['function'], '%line' => $trace[0]['line']));
     return $object;
   }
 

+ 5 - 0
tripal_chado/includes/TripalFields/chado_linker__contact/chado_linker__contact.inc

@@ -137,6 +137,11 @@ class chado_linker__contact extends ChadoField {
     $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
     $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
 
+    // If we don't have a chado record return before creating a stub for this field!
+    if (!$record) {
+      return;
+    }
+    
     // Set some defaults for the empty record.
     $entity->{$field_name}['und'][0] = array(
       'value' => array(),

+ 5 - 0
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference.inc

@@ -129,6 +129,11 @@ class sbo__database_cross_reference extends ChadoField {
     $accession_term = chado_get_semweb_term('dbxref', 'accession');
     $dburl_term = chado_get_semweb_term('db', 'url');
 
+    // If we don't have a chado record return before creating a stub for this field!
+    if (!$record) {
+      return;
+    }
+    
     // Set some defaults for the empty record.
     $entity->{$field_name}['und'][0] = array(
       'value' => '',

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

@@ -384,6 +384,11 @@ class sbo__relationship extends ChadoField {
     $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
     $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
 
+    // If we don't have a chado record return before creating a stub for this field!
+    if (!$record) {
+      return;
+    }
+    
     // Not all tables have the columns named 'subject_id' and 'object_id'.
     // some have variations on that name and we need to determine what they are.
     $fkeys = $schema['foreign keys'];

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

@@ -151,8 +151,8 @@ class schema__publication_widget extends ChadoFieldWidget {
     // write a record.
     if (!$title) {
       $form_state['values'][$field_name]['und'][$delta]['value'] = 'delete_me';
-      $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $fkey] = '';
-      $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__pub_id'] = '';
+      $form_state['values'][$field_name]['und'][$delta][$pub_item_id] = '';
+      $form_state['values'][$field_name]['und'][$delta]['value'] = '';
     }
   }
 

+ 10 - 5
tripal_chado/includes/TripalFields/sep__protocol/sep__protocol.inc

@@ -117,16 +117,21 @@ class sep__protocol extends ChadoField {
     $base_table = $this->instance['settings']['base_table'];
     $linker_field = 'chado-' . $field_table . '__' . $field_column;
 
-    // Set some defaults for the empty record.
-    $entity->{$field_name}['und'][0] = [
-      'value' => [],
-    ];
-
     if (!$record) {
       return;
     }
     
     $protocol = $record->{$field_column};
+    // If this record does not have a protcol then just return.
+    if (!$protocol) {
+      return;
+    }
+    
+    // Set some defaults for the empty record.
+    $entity->{$field_name}['und'][0] = [
+      'value' => [],
+    ];
+    
     $entity_id = $record->entity_id;
 
     // Get the Protocol controlled vocabulary terms.

+ 11 - 10
tripal_chado/includes/TripalFields/sep__protocol/sep__protocol_formatter.inc

@@ -32,24 +32,25 @@ class sep__protocol_formatter extends ChadoFieldFormatter {
    */
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
 
-    if (count($items) > 0) {
+    if ($items[0]['value']) {
       
       $protocol_name_term = chado_get_semweb_term('protocol', 'name');
       $protocol_type_term = chado_get_semweb_term('protocol', 'type_id');    
 
       $protocol_name =  $items[0]['value'][$protocol_name_term];
       $content = $protocol_name;
-      list($entity_type, $entity_id) = explode(':', $items[0]['value']['entity_id']);
-      if ($entity_id) {
-        $content = l($protocol_name, 'bio_data/' . $entity_id);
+      if (array_key_exists('entity_id', $items[0]['value'])) {
+        list($entity_type, $entity_id) = explode(':', $items[0]['value']['entity_id']);
+        if ($entity_id) {
+          $content = l($protocol_name, 'bio_data/' . $entity_id);
+        }
       }
+      //cardinality for this field is 1
+      $element[0] = [
+        '#type' => 'markup',
+        '#markup' => $content,
+      ];
     }
-
-    //cardinality for this field is 1
-    $element[0] = [
-      '#type' => 'markup',
-      '#markup' => $content,
-    ];
   }
 
 

+ 8 - 54
tripal_chado/includes/TripalFields/sep__protocol/sep__protocol_widget.inc

@@ -16,59 +16,7 @@ class sep__protocol_widget extends ChadoFieldWidget {
   public static $field_types = ['sep__protocol'];
 
   /**
-   * Provides the form for editing of this field.
-   *
-   * This function corresponds to the hook_field_widget_form()
-   * function of the Drupal Field API.
-   *
-   * This form is diplayed when the user creates a new entity or edits an
-   * existing entity.  If the field is attached to the entity then the form
-   * provided by this function will be displayed.
-   *
-   * At a minimum, the form must have a 'value' element.  For Tripal, the
-   * 'value' element of a field always corresponds to the value that is
-   * presented to the end-user either directly on the page (with formatting)
-   * or via web services, or some other mechanism.  However, the 'value' is
-   * sometimes not enough for a field.  For example, the Tripal Chado module
-   * maps fields to table columns and sometimes those columns are foreign keys
-   * therefore, the Tripal Chado modules does not just use the 'value' but adds
-   * additional elements to help link records via FKs.  But even in this case
-   * the 'value' element must always be present in the return form and in such
-   * cases it's value should be set equal to that added in the 'load' function.
-   *
-   * @param $widget
-   * @param $form
-   *   The form structure where widgets are being attached to. This might be a
-   *   full form structure, or a sub-element of a larger form.
-   * @param $form_state
-   *   An associative array containing the current state of the form.
-   * @param $langcode
-   *   The language associated with $items.
-   * @param $items
-   *   Array of default values for this field.
-   * @param $delta
-   *   The order of this item in the array of subelements (0, 1, 2, etc).
-   * @param $element
-   * A form element array containing basic properties for the widget:
-   *  - #entity_type: The name of the entity the field is attached to.
-   *  - #bundle: The name of the field bundle the field is contained in.
-   *  - #field_name: The name of the field.
-   *  - #language: The language the field is being edited in.
-   *  - #field_parents: The 'parents' space for the field in the form. Most
-   *    widgets can simply overlook this property. This identifies the location
-   *    where the field values are placed within $form_state['values'], and is
-   *    used to access processing information for the field through the
-   *    field_form_get_state() and field_form_set_state() functions.
-   *  - #columns: A list of field storage columns of the field.
-   *  - #title: The sanitized element label for the field instance, ready for
-   *    output.
-   *  - #description: The sanitized element description for the field instance,
-   *    ready for output.
-   *  - #required: A Boolean indicating whether the element value is required;
-   *    for required multiple value fields, only the first widget's values are
-   *    required.
-   *  - #delta: The order of this item in the array of subelements; see
-   *    $delta above
+   * @see TripalFieldWidget::form()
    */
   public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
@@ -137,7 +85,13 @@ class sep__protocol_widget extends ChadoFieldWidget {
     
     // Make sure the value is set to the organism_id
     $protocol_id = $form_state['values'][$field_name]['und'][0][$linker_field];
-    $form_state['values'][$field_name]['und'][0]['value'] = $protocol_id;
+    if ($protocol_id) {
+      $form_state['values'][$field_name]['und'][0]['value'] = $protocol_id;
+    }
+    else {
+      $form_state['values'][$field_name]['und'][0]['value'] = '__NULL__';
+      $form_state['values'][$field_name]['und'][0][$linker_field] = '__NULL__';
+    }
   }
 
   /**