Преглед изворни кода

Fixed formWidgetSubmit for all fields... some still need debuggin

Stephen Ficklin пре 8 година
родитељ
комит
f6822d6ea3

+ 7 - 5
tripal/includes/TripalEntityUIController.inc

@@ -435,11 +435,13 @@ function tripal_entity_form_ajax_callback($form, $form_state) {
          if (!preg_match('/^\d+$/', $delta)) {
            continue;
          }
-         $field = $field_form['#field'];
-         $field_type = $field['type'];
-         if (class_exists($field_type)) {
-           $tfield = new $field_type($field, $instance);
-           $tfield->widgetFormSubmit($form, $form_state, $entity_type, $entity, $langcode, $delta);
+         if (array_key_exists('#field', $field_form)) {
+           $field = $field_form['#field'];
+           $field_type = $field['type'];
+           if (class_exists($field_type)) {
+             $tfield = new $field_type($field, $instance);
+             $tfield->widgetFormSubmit($form, $form_state, $entity_type, $entity, $langcode, $delta);
+           }
          }
        }
      }

+ 8 - 2
tripal/includes/TripalField.inc

@@ -366,13 +366,19 @@ class TripalField {
       '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
     );
     $widget['#field'] = $this->field;
+    $widget['#instance'] = $this->instance;
     $widget['#element_validate'] = array('tripal_field_widget_form_validate');
   }
 
   /**
+   * Performs validation of the widgetForm.
    *
-   * @param unknown $form
-   * @param unknown $form_state
+   * Use this validate to ensure that form values are entered correctly.  Note
+   * this is different from the validate() function which ensures that the
+   * field data meets expectations.
+   *
+   * @param $form
+   * @param $form_state
    */
   public function widgetFormValidate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
 

+ 24 - 17
tripal/includes/tripal.fields.inc

@@ -215,8 +215,9 @@ function tripal_form_field_ui_field_overview_form_alter(&$form, &$form_state, $f
 function tripal_field_settings_form($field, $instance, $has_data) {
   $form = array();
   $field_type = $field['type'];
-  $is_loaded = tripal_load_include_field_type($field_type);
-  if ($is_loaded) {
+  //$is_loaded = tripal_load_include_field_type($field_type);
+  tripal_load_include_field_type($field_type);
+  if (class_exists($field_type)) {
     $tfield = new $field_type($field, $instance);
     $form = $tfield->globalSettingsForm($field, $instance, $has_data);
   }
@@ -228,8 +229,8 @@ function tripal_field_settings_form($field, $instance, $has_data) {
 function tripal_field_instance_settings_form($field, $instance) {
   $form = array();
   $field_type = $field['type'];
-  $is_loaded = tripal_load_include_field_type($field_type);
-  if ($is_loaded) {
+  tripal_load_include_field_type($field_type);
+  if (class_exists($field_type)) {
     $tfield = new $field_type($field, $instance);
     $form = $tfield->instanceSettingsForm();
   }
@@ -242,8 +243,11 @@ function tripal_field_instance_settings_form_validate($form, &$form_state) {
   $field = $form['#field'];
   $instance = $form['#instance'];
   $field_type = $field['type'];
-  $tfield = new $field_type($field, $instance);
-  $form = $tfield->instanceSettingsFormValidate($form, $form_state);
+  tripal_load_include_field_type($field_type);
+  if (class_exists($field_type)) {
+    $tfield = new $field_type($field, $instance);
+    $form = $tfield->instanceSettingsFormValidate($form, $form_state);
+  }
 }
 
 /**
@@ -255,10 +259,13 @@ function tripal_field_widget_form_validate($form, &$form_state) {
   $langcode = $form['#language'];
   $delta = $form['#delta'];
   $field = $form['#field'];
-  $instance = $form['#instance'];
   $field_type = $field['type'];
-  $tfield = new $field_type($field, $instance);
-  $form = $tfield->widgetFormValidate($form, $form_state, $entity_type, $entity, $langcode, $delta);
+  tripal_load_include_field_type($field_type);
+  if (class_exists($field_type)) {
+    $instance = $form['#instance'];
+    $tfield = new $field_type($field, $instance);
+    $form = $tfield->widgetFormValidate($form, $form_state, $entity_type, $entity, $langcode, $delta);
+  }
 }
 
 
@@ -273,8 +280,8 @@ function tripal_field_settings_form_validate($form, &$form_state) {
   $field = $form['#field'];
   $instance = $form['#instance'];
   $field_type = $field['type'];
-  $is_loaded = tripal_load_include_field_type($field_type);
-  if ($is_loaded) {
+  tripal_load_include_field_type($field_type);
+  if (class_exists($field_type)) {
     $tfield = new $field_type($field, $instance);
     $form = $tfield->globalSettingsFormValidate($field, $instance, $form, $form_state);
   }
@@ -288,8 +295,8 @@ function tripal_field_formatter_settings_summary($field, $instance, $view_mode)
 
   $summary = '';
   $field_type = $field['type'];
-  $is_loaded = tripal_load_include_field_type($field_type);
-  if ($is_loaded) {
+  tripal_load_include_field_type($field_type);
+  if (class_exists($field_type)) {
     $tfield = new $field_type($field, $instance);
     $form = $tfield->formatterSettingsSummary($view_mode);
   }
@@ -304,8 +311,8 @@ function tripal_formatter_settings_form($field, $instance,
 
   $form = array();
   $field_type = $field['type'];
-  $is_loaded = tripal_load_include_field_type($field_type);
-  if ($is_loaded) {
+  tripal_load_include_field_type($field_type);
+  if (class_exists($field_type)) {
     $tfield = new $field_type($field, $instance);
     $form = $tfield->formatterSettingsForm($view_mode, $form, $form_state);
   }
@@ -320,8 +327,8 @@ function tripal_field_widget_form(&$form, &$form_state, $field,
     $instance, $langcode, $items, $delta, $element) {
   $widget = $element;
   $field_type = $field['type'];
-  $is_loaded = tripal_load_include_field_type($field_type);
-  if ($is_loaded) {
+  tripal_load_include_field_type($field_type);
+  if (class_exists($field_type)) {
     $tfield = new $field_type($field, $instance);
     $tfield->widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
   }

+ 10 - 4
tripal_chado/api/modules/tripal_chado.pub.api.inc

@@ -1008,6 +1008,10 @@ function tripal_pub_create_citation($pub) {
  *   'URL'. All keys are term names in the Tripal Publication Ontology :TPUB.
  */
 function tripal_get_minimal_pub_info($pub) {
+  if (!$pub) {
+    return array();
+  }
+
   // Chado has a null pub as default.  We don't return anything for this.
   if ($pub->uniquename == 'null') {
     return array();
@@ -1093,11 +1097,13 @@ function tripal_get_minimal_pub_info($pub) {
     'return_array' => 1,
     'include_fk' => array(),
   );
-  $urls = chado_generate_var('pubprop', $values, $options);
-  $urls = chado_expand_var($urls, 'field', 'pubprop.value');
   $url = '';
-  if (count($urls) > 0) {
-    $url = $urls[0]->value;
+  $urls = chado_generate_var('pubprop', $values, $options);
+  if ($urls) {
+    $urls = chado_expand_var($urls, 'field', 'pubprop.value');
+    if (count($urls) > 0) {
+      $url = $urls[0]->value;
+    }
   }
   return array(
     'Title' => $pub->title,

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

@@ -599,6 +599,8 @@ function chado_expand_var($object, $type, $to_expand, $table_options = array())
       TRIPAL_ERROR,
       'Cannot pass non array as argument, $object, to chado_expand_var function.',
       array());
+    $d=debug_backtrace();
+    dpm($d[0]);
     return $object;
   }
 

+ 17 - 20
tripal_chado/includes/TripalFields/chado_base__dbxref_id.inc

@@ -213,26 +213,23 @@ class chado_base__dbxref_id extends TripalField {
     $field_table = $this->field['settings']['chado_table'];
     $field_column = $this->field['settings']['chado_column'];
 
-    // Get the field values.
-    foreach ($items as $delta => $values) {
-      $fk_val = $values['chado-' . $field_table . '__' . $field_column];
-      $db_id = $values['db_id'];
-      $accession = $values['accession'];
-      $version = $values['version'];
-
-      // If user did not select a database, we want to remove dbxref_id from the
-      // field.
-      if (!$db_id) {
-        $items[$delta]['chado-' . $field_table . '__dbxref_id'] = '__NULL__';
-      }
-      // If the dbxref_id does not match the db_id + accession then the user
-      // has selected a new dbxref record and we need to update the hidden
-      // value accordingly.
-      if ($db_id and $accession) {
-        $dbxref = chado_generate_var('dbxref', array('db_id' => $db_id, 'accession' => $accession));
-        if ($dbxref and $dbxref->dbxref_id != $fk_val) {
-          $items[$delta]['chado-' . $field_table . '__dbxref_id'] = $dbxref->dbxref_id;
-        }
+    $fk_val = $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__' . $field_column];
+    $db_id = $form_state['values'][$field_name][$langcode][$delta]['db_id'];
+    $accession = $form_state['values'][$field_name][$langcode][$delta]['accession'];
+    $version = $form_state['values'][$field_name][$langcode][$delta]['version'];
+
+    // If user did not select a database, we want to remove dbxref_id from the
+    // field.
+    if (!$db_id) {
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__dbxref_id'] = '__NULL__';
+    }
+    // If the dbxref_id does not match the db_id + accession then the user
+    // has selected a new dbxref record and we need to update the hidden
+    // value accordingly.
+    if ($db_id and $accession) {
+      $dbxref = chado_generate_var('dbxref', array('db_id' => $db_id, 'accession' => $accession));
+      if ($dbxref and $dbxref->dbxref_id != $fk_val) {
+        $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__dbxref_id'] = $dbxref->dbxref_id;
       }
     }
   }

+ 5 - 5
tripal_chado/includes/TripalFields/chado_feature__md5checksum.inc

@@ -77,17 +77,17 @@ class chado_feature__md5checksum  extends TripalField {
     $field_column = $field['settings']['chado_column'];
 
     // Get the residues so we can calculate teh length.
-    $residues = $form_state['values']['feature__residues']['und'][0]['chado-feature__residues'];
+    $residues = $form_state['values']['feature__residues'][$langcode][0]['chado-feature__residues'];
 
     if ($residues) {
+      // Remove spaces and new lines from the residues string.
       $residues = preg_replace('/\s/', '', $residues);
-      $form_state['values']['feature__residues']['und'][0]['chado-feature__residues'] = $residues;
-      $items[0]['chado-feature__md5checksum'] = md5($residues);
+      $form_state['values']['feature__residues'][$langcode][0]['chado-feature__residues'] = $residues;
+      $form_state['values'][$field_name][$langcode][$delta]['chado-feature__md5checksum'] = md5($residues);
     }
     else {
       // Otherwise, remove the md5 value
-      $items[0]['chado-feature__md5checksum'] = '__NULL__';
+      $form_state['values'][$field_name][$langcode][$delta]['chado-feature__md5checksum'] = '__NULL__';
     }
   }
-
 }

+ 4 - 2
tripal_chado/includes/TripalFields/chado_feature__residues.inc

@@ -103,11 +103,13 @@ class chado_feature__residues extends TripalField {
    */
   public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
 
+    $field_name = $this->field['field_name'];
+
     // Remove any white spaces.
-    $residues = $items[0]['chado-feature__residues'];
+    $residues = $form_state['values'][$field_name][$langcode][$delta]['chado-feature__residues'];
     if ($residues) {
       $residues = preg_replace('/\s/', '', $residues);
-      $items[0]['chado-feature__residues'] = $residues;
+      $form_state['values'][$field_name][$langcode][$delta]['chado-feature__residues'] = $residues;
     }
   }
 

+ 1 - 1
tripal_chado/includes/TripalFields/chado_linker__contact.inc

@@ -189,7 +189,7 @@ class chado_linker__contact extends TripalField {
     if (!$name and $contact_id) {
       $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $fkey] = '';
       $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__contact_id'] = '';
-    };
+    }
   }
 
   /**

+ 3 - 5
tripal_chado/includes/TripalFields/chado_linker__cvterm.inc

@@ -203,12 +203,10 @@ class chado_linker__cvterm extends TripalField {
 
   }
 
-  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+  public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
 
-    $field_name = $element['#field_name'];
-    $delta = $element['#delta'];
-    $table_name = $element['#table_name'];
-    $fkey = $element['#fkey_field'];
+    $field_name = $this->field['field_name'];
+    $field_type = $this->field['type'];
 
     // If the form ID is field_ui_field_edit_form, then the user is editing the
     // field's values in the manage fields form of Drupal.  We don't want

+ 21 - 25
tripal_chado/includes/TripalFields/chado_linker__dbxref.inc

@@ -268,33 +268,29 @@ class chado_linker__dbxref extends TripalField {
     $fkey = $fkeys[0];
 
     // Get the field values.
-    foreach ($items as $delta => $values) {
-
-      // Get the field values.
-      $dbxref_id = $values['chado-' . $field_table . '__dbxref_id'];
-      $db_id = $values['db_id'];
-      $accession = $values['accession'];
-      $version = $values['version'];
-      $description = $values['description'];
-
-      // If the dbxref_id does not match the db_id + accession then the user
-      // has selected a new dbxref record and we need to update the hidden
-      // value accordingly.
-      if ($db_id and $accession) {
-        $dbxref = chado_generate_var('dbxref', array('db_id' => $db_id, 'accession' => $accession));
-        if ($dbxref and $dbxref->dbxref_id != $dbxref_id) {
-          $items[$delta]['chado-' . $table_name . '__dbxref_id'] = $dbxref->dbxref_id;
-          $items[$delta]['dbxref_id'] = $dbxref->dbxref_id;
-        }
-      }
-      // If the db_id and accession are not set, then remove the linker FK
-      // value to the base table, but leave the primary key so the record
-      // can be deleted.
-      else {
-        $items[$delta]['chado-' . $table_name . '__' . $fkey] = '';
-        $items[$delta]['chado-' . $table_name . '__dbxref_id'] = '';
+    $dbxref_id = $form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__dbxref_id'];
+    $db_id = $form_state['values'][$field_name][$langcode][$delta]['db_id'];
+    $accession = $form_state['values'][$field_name][$langcode][$delta]['accession'];
+    $version = $form_state['values'][$field_name][$langcode][$delta]['version'];
+    $description = $form_state['values'][$field_name][$langcode][$delta]['description'];
+
+    // If the dbxref_id does not match the db_id + accession then the user
+    // has selected a new dbxref record and we need to update the hidden
+    // value accordingly.
+    if ($db_id and $accession) {
+      $dbxref = chado_generate_var('dbxref', array('db_id' => $db_id, 'accession' => $accession));
+      if ($dbxref and $dbxref->dbxref_id != $dbxref_id) {
+        $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__dbxref_id'] = $dbxref->dbxref_id;
+        $form_state['values'][$field_name][$langcode][$delta]['dbxref_id'] = $dbxref->dbxref_id;
       }
     }
+    // If the db_id and accession are not set, then remove the linker FK
+    // value to the base table, but leave the primary key so the record
+    // can be deleted.
+    else {
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $fkey] = '';
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__dbxref_id'] = '';
+    }
   }
 
   /**

+ 6 - 7
tripal_chado/includes/TripalFields/chado_linker__prop.inc

@@ -177,13 +177,12 @@ class chado_linker__prop extends TripalField {
   public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
 
     $field_table = $this->field['settings']['chado_table'];
-    foreach ($items AS $delta => $item) {
-      // Don't save if there is no value for prop
-      if (!trim($item['chado-' . $field_table . '__' . 'value'])) {
-        foreach($item AS $key => $value) {
-          if (preg_match('/^chado-/', $key)) {
-            $items[$delta][$key] = '__NULL__';
-          }
+
+    // Don't save if there is no value for prop
+    if (!trim($form_state['values'][$field_name][$langcode][$delta]['chado-' . $field_table . '__' . 'value'])) {
+      foreach($form_state['values'][$field_name][$langcode][$delta] AS $key => $value) {
+        if (preg_match('/^chado-/', $key)) {
+          $form_state['values'][$field_name][$langcode][$delta][$key] = '__NULL__';
         }
       }
     }

+ 7 - 5
tripal_chado/includes/TripalFields/chado_linker__prop_adder.inc

@@ -165,6 +165,7 @@ class chado_linker__prop_adder extends TripalField {
       if (!preg_match('/^\d+$/', $cardinality) or $cardinality < 0) {
         form_set_error("$field_name][$langcode][$delta][wrapper][cardinality", "Please provide positive number for the number of values.");
       }
+
     }
   }
 
@@ -172,13 +173,18 @@ class chado_linker__prop_adder extends TripalField {
    * @see TripalField::widgetFormValidate
    */
   public function validate($entity_type, $entity, $field, $items, &$errors) {
-    // Nothing to validate.
+    // This form doesn't manage data in the database so we don't need to
+    // validate anything here.
   }
 
   /**
    * @see TripalField::widgetFormSubmit()
    */
   public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+    // Because we're going to add a new property we want to rebuild the form
+    // rather than have it fully submit.
+    $form_state['rebuild'] = TRUE;
+
     return;
     // We will never have more than one item for this field at a time, so
     // delta is always zero.
@@ -191,10 +197,6 @@ class chado_linker__prop_adder extends TripalField {
       return;
     }
 
-    // Because we're going to add a new property we want to rebuild the form
-    // rather than have it fully submit.
-    $form_state['rebuild'] = TRUE;
-
     // Get the table and base table.
     $base_table = $this->field['settings']['base_table'];
 

+ 24 - 26
tripal_chado/includes/TripalFields/chado_linker__pub.inc

@@ -131,7 +131,6 @@ class chado_linker__pub extends TripalField {
    */
   public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
 
-
     // Get the FK column that links to the base table.
     $table_name = $this->field['settings']['chado_table'];
     $base_table = $this->field['settings']['base_table'];
@@ -139,35 +138,34 @@ class chado_linker__pub extends TripalField {
     $pkey = $schema['primary key'][0];
     $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
     $fkey = $fkeys[0];
+    $field_name = $this->field['field_name'];
 
     // Get the field values.
-    foreach ($items as $delta => $values) {
-      $fkey_value = $values['value'];
-      $pub_id = $values['chado-' . $table_name . '__pub_id'];
-      $uname = $values['uniquename'];
-
-      // If the user provided a uniquename then we want to set the foreign key
-      // value to be the chado_record_id
-      if ($uname and !$pub_id) {
-        $pub = chado_generate_var('pub', array('uniquename' => $uname));
-        $items[$delta]['chado-' . $table_name . '__pub_id'] = $pub->pub_id;
-      }
+    $fkey_value = $form_state['values'][$field_name][$langcode][$delta]['value'];
+    $pub_id = $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id'];
+    $uname = $form_state['values'][$field_name][$langcode][$delta]['uniquename'];
+
+    // If the user provided a uniquename then we want to set the foreign key
+    // value to be the chado_record_id
+    if ($uname and !$pub_id) {
+      $pub = chado_generate_var('pub', array('uniquename' => $uname));
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id'] = $pub->pub_id;
+    }
 
-      // In the widgetFrom function we automatically add the foreign key
-      // record.  But if the user did not provide a publication we want to take
-      // it out so that the Chado field_storage infrastructure won't try to
-      // write a record.
-      if (!$uname and !$pub_id) {
-        $items[$delta]['chado-' . $table_name . '__' . $fkey] = '';
-      }
+    // In the widgetFrom function we automatically add the foreign key
+    // record.  But if the user did not provide a publication we want to take
+    // it out so that the Chado field_storage infrastructure won't try to
+    // write a record.
+    if (!$uname and !$pub_id) {
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $fkey] = '';
+    }
 
-      // If the user removed the publication from the pub_uniquename field
-      // then we want to clear out the rest of the hidden values.
-      // Leave the primary key so the record can be deleted.
-      if (!$uname and $pub_id) {
-        $items[$delta]['chado-' . $table_name . '__' . $fkey] = '';
-        $items[$delta]['chado-' . $table_name . '__pub_id'] = '';
-      }
+    // If the user removed the publication from the pub_uniquename field
+    // then we want to clear out the rest of the hidden values.
+    // Leave the primary key so the record can be deleted.
+    if (!$uname and $pub_id) {
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $fkey] = '';
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id'] = '';
     }
   }
 

+ 40 - 41
tripal_chado/includes/TripalFields/chado_linker__relationship.inc

@@ -596,52 +596,51 @@ return;
     $schema = chado_get_schema($field_table);
     $fkeys = $schema['foreign keys'];
 
-    foreach ($items as $delta => $item) {
-      $type_name = array_key_exists('type_name', $item) ? $item['type_name'] : '';
-      $subject_id = $item[$field_table . '__subject_id'];
-      $object_id = $item[ $field_table . '__object_id'];
-      $type_id = $item[$field_table . '__type_id'];
+    $type_name = array_key_exists('type_name', $item) ? $item['type_name'] : '';
+    $subject_id = $form_state['values'][$field_name][$langcode][$delta][$field_table . '__subject_id'];
+    $object_id = $form_state['values'][$field_name][$langcode][$delta][ $field_table . '__object_id'];
+    $type_id = $form_state['values'][$field_name][$langcode][$delta][$field_table . '__type_id'];
 
-      $subject_name = $item['subject_name'];
-      $object_name = $item['object_name'];
-
-      // If the row is empty then skip this one, there's nothing to validate.
-      if (!($type_id or !$type_name) and !$subject_name and !$object_name) {
-        continue;
-      }
+    $subject_name = $form_state['values'][$field_name][$langcode][$delta]['subject_name'];
+    $object_name = $form_state['values'][$field_name][$langcode][$delta]['object_name'];
 
-      // Get the subject ID.
-      $subject_id = '';
-      $fkey_rcolumn = $fkeys[$base_table]['columns']['subject_id'];
-      $matches = array();
-      if (preg_match('/\[id: (\d+)\]/', $subject_name, $matches)) {
-        $subject_id =  $matches[1];
-      }
-      else {
-        $values = array('uniquename' => $subject_name);
-        $subject = chado_select_record($base_table, array($fkey_rcolumn), $values);
-        $subject_id = $subject[0]->$fkey_rcolumn;
-      }
+    // If the row is empty then skip this one, there's nothing to validate.
+    if (!($type_id or !$type_name) and !$subject_name and !$object_name) {
+      return;
+    }
 
-      // Get the object ID.
-      $object_id = '';
-      $fkey_rcolumn = $fkeys[$base_table]['columns']['object_id'];
-      $matches = array();
-      if (preg_match('/\[id: (\d+)\]/', $object_name, $matches)) {
-        $object_id = $matches[1];
-      }
-      else {
-        $values = array('uniquename' => $object_name);
-        $object = chado_select_record($base_table, array($fkey_rcolumn), $values);
-        $object_id = $object[0]->$fkey_rcolumn;
-      }
+    // Get the subject ID.
+    $subject_id = '';
+    $fkey_rcolumn = $fkeys[$base_table]['columns']['subject_id'];
+    $matches = array();
+    if (preg_match('/\[id: (\d+)\]/', $subject_name, $matches)) {
+      $subject_id =  $matches[1];
+    }
+    else {
+      $values = array('uniquename' => $subject_name);
+      $subject = chado_select_record($base_table, array($fkey_rcolumn), $values);
+      $subject_id = $subject[0]->$fkey_rcolumn;
+    }
 
-      // Set the IDs according to the values that were determined above.
-      $items[$delta][$field_table . '__subject_id'] = $subject_id;
-      $items[$delta][$field_table . '__object_id'] = $object_id;
-      $items[$delta][$field_table . '__type_id'] = $type_name;
-      $items[$delta][$field_table . '__rank'] = $item['_weight'];
+    // Get the object ID.
+    $object_id = '';
+    $fkey_rcolumn = $fkeys[$base_table]['columns']['object_id'];
+    $matches = array();
+    if (preg_match('/\[id: (\d+)\]/', $object_name, $matches)) {
+      $object_id = $matches[1];
+    }
+    else {
+      $values = array('uniquename' => $object_name);
+      $object = chado_select_record($base_table, array($fkey_rcolumn), $values);
+      $object_id = $object[0]->$fkey_rcolumn;
     }
+
+    // Set the IDs according to the values that were determined above.
+    $form_state['values'][$field_name][$langcode][$delta][$field_table . '__subject_id'] = $subject_id;
+    $form_state['values'][$field_name][$langcode][$delta][$field_table . '__object_id'] = $object_id;
+    $form_state['values'][$field_name][$langcode][$delta][$field_table . '__type_id'] = $type_name;
+    $form_state['values'][$field_name][$langcode][$delta][$field_table . '__rank'] = $item['_weight'];
+
   }
   /**
    * @see TripalField::load()

+ 37 - 41
tripal_chado/includes/TripalFields/chado_linker__synonym.inc

@@ -219,52 +219,48 @@ class chado_linker__synonym extends TripalField {
     $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
     $fkey = $fkeys[0];
 
-    // Get the field values.
-    foreach ($items as $delta => $values) {
-
-      $record_id = $values['chado-' . $table_name . '__' . $pkey];
-      $fkey_value = $values['chado-' . $table_name . '__' . $fkey];
-      $synonym_id = $values['chado-' . $table_name . '__synonym_id'];
-      $pub_id = $values['chado-' . $table_name . '__pub_id'];
-      $is_current = $values['chado-' . $table_name . '__is_current'];
-      $is_internal = $values['chado-' . $table_name . '__is_internal'];
-      $syn_name = $values['name'];
-      $syn_type = $values['type_id'];
-
-      // If the user provided a $syn_name and a $syn_type then we want to set
-      // the foreign key value to be the chado_record_id.
-      if ($syn_name and $syn_type) {
-
-        // Get the synonym. If one with the same name and type is already present
-        // then use that. Otherwise, insert a new one.
-        if (!$synonym_id) {
-          $synonym = chado_generate_var('synonym', array('name' => $syn_name, 'type_id' => $syn_type));
-          if (!$synonym) {
-            $synonym = chado_insert_record('synonym', array(
-              'name' => $syn_name,
-              'type_id' => $syn_type,
-              'synonym_sgml' => '',
-            ));
-            $synonym = (object) $synonym;
-          }
-
-          // Set the synonym_id and FK value
-          $items[$delta]['chado-' . $table_name . '__synonym_id'] = $synonym->synonym_id;
+    $record_id = $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $pkey];
+    $fkey_value = $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $fkey];
+    $synonym_id = $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__synonym_id'];
+    $pub_id = $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id'];
+    $is_current = $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__is_current'];
+    $is_internal = $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__is_internal'];
+    $syn_name = $form_state['values'][$field_name][$langcode][$delta]['name'];
+    $syn_type = $form_state['values'][$field_name][$langcode][$delta]['type_id'];
+
+    // If the user provided a $syn_name and a $syn_type then we want to set
+    // the foreign key value to be the chado_record_id.
+    if ($syn_name and $syn_type) {
+
+      // Get the synonym. If one with the same name and type is already present
+      // then use that. Otherwise, insert a new one.
+      if (!$synonym_id) {
+        $synonym = chado_generate_var('synonym', array('name' => $syn_name, 'type_id' => $syn_type));
+        if (!$synonym) {
+          $synonym = chado_insert_record('synonym', array(
+            'name' => $syn_name,
+            'type_id' => $syn_type,
+            'synonym_sgml' => '',
+          ));
+          $synonym = (object) $synonym;
         }
 
-        if (!$pub_id) {
-          $pub = chado_generate_var('pub', array('uniquename' => 'null'));
-          $items[$delta]['chado-' . $table_name . '__pub_id'] = $pub->pub_id;
-        }
+        // Set the synonym_id and FK value
+        $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__synonym_id'] = $synonym->synonym_id;
       }
-      else {
-        // If the $syn_name is not set, then remove the linker FK value to the base table.
-        $items[$delta]['chado-' . $table_name . '__' . $fkey] = '';
-        $items[$delta]['chado-' . $table_name . '__synonym_id'] = '';
-        $items[$delta]['chado-' . $table_name . '__is_internal'] = '';
-        $items[$delta]['chado-' . $table_name . '__is_current'] = '';
+
+      if (!$pub_id) {
+        $pub = chado_generate_var('pub', array('uniquename' => 'null'));
+        $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id'] = $pub->pub_id;
       }
     }
+    else {
+      // If the $syn_name is not set, then remove the linker FK value to the base table.
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $fkey] = '';
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__synonym_id'] = '';
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__is_internal'] = '';
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__is_current'] = '';
+    }
   }
 
   /**