Browse Source

Fixed issue with widgetFormValidate in TripalField class

Stephen Ficklin 8 years ago
parent
commit
c0c407fbad

+ 16 - 22
tripal/includes/TripalEntityUIController.inc

@@ -322,7 +322,6 @@ function tripal_view_entity($entity, $view_mode = 'full') {
   *
   */
  function tripal_entity_form($form, &$form_state, $term_id = '', $entity = NULL) {
-
    $bundle_name = 'bio_data_' . $term_id;
 
    // Add a vertical tabs element
@@ -372,7 +371,6 @@ function tripal_view_entity($entity, $view_mode = 'full') {
      '#name' => 'cancel_data',
      '#weight' => 1001,
      '#limit_validation_errors' => array(array('')),
-     '#submit' => array('tripal_entity_form_submit'),
    );
 
    // The entity object must be added to the $form_state in order for
@@ -381,6 +379,7 @@ function tripal_view_entity($entity, $view_mode = 'full') {
 
    $form['#prefix'] = "<div id='$bundle_name-entity-form'>";
    $form['#suffix'] = "</div>";
+   $form['#submit'][] = 'tripal_entity_form_submit';
    return $form;
  }
  /**
@@ -426,26 +425,21 @@ function tripal_entity_form_ajax_callback($form, $form_state) {
      $form_state['redirect'] = 'bio_data/' . $entity->id .'/delete';
      return;
    }
-
-   // Allow the fields to perform actions prior to submit by calling
-   // a hook_field_submit() functino.
-   $fields = field_info_instances('TripalEntity', $entity->bundle);
-   foreach ($fields as $field_name => $instance) {
-     $field = field_info_field($field_name);
-     $module = $field['module'];
-     $function = $module . '_field_submit';
-     if (function_exists($function)) {
-       // Get the items from the form_state and allow the caller to alter them.
-       $items = array();
-       $langcode = 'und';
-       field_default_extract_form_values('TripalEntity', $entity, $field,
-           $instance, $langcode, $items, $form, $form_state);
-       $function('TripalEntity', $entity, $field, $instance, $langcode, $items,
-           $form, $form_state);
-       // Copy any updated items into the $form_state 'values' array.
-       foreach ($items as $delta => $item) {
-         foreach ($item as $subfield => $value) {
-           $form_state['values'][$field_name][$langcode][$delta][$subfield] = $value;
+   // Allow the fields to perform actions prior to submit.
+   $instances = field_info_instances('TripalEntity', $entity->bundle);
+   $langcode = 'und';
+   foreach ($instances as $field_name => $instance) {
+     $entity_type = $instance['entity_type'];
+     if($entity_type == 'TripalEntity') {
+       foreach ($form[$field_name][$langcode] as $delta => $field_form) {
+         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);
          }
        }
      }

+ 15 - 6
tripal/includes/TripalField.inc

@@ -365,14 +365,21 @@ class TripalField {
       '#type' => 'value',
       '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
     );
-
+    $widget['#field'] = $this->field;
+    $widget['#element_validate'] = array('tripal_field_widget_form_validate');
   }
 
   /**
-   *  Perform validation of the widget_form when adding or editing the entity.
    *
-   *  This function corresponds to the hook_field_validate() function of the
-   *  Drupal Field API.
+   * @param unknown $form
+   * @param unknown $form_state
+   */
+  public function widgetFormValidate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+
+  }
+
+  /**
+   *  Perform validation of the field regardless how it is updated.
    *
    *  Any errors encountered should be indicatd by adding a value to the $errors
    *  array according to the instructions below.
@@ -399,10 +406,11 @@ class TripalField {
    *      - message: The human readable message to be displayed.
    *
    */
-  public function widgetFormValidate($entity_type, $entity, $field, $items, &$errors) {
+  public function validate($entity_type, $entity, $field, $items, &$errors) {
 
   }
 
+
   /**
    * Performs extra commands when the entity form is submitted.
    *
@@ -438,7 +446,8 @@ class TripalField {
    *  @param $form_state.
    *    The form state array.
    */
-  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+  public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+
   }
 
   /**

+ 5 - 8
tripal/includes/TripalFields/content_type.inc

@@ -44,13 +44,10 @@ class content_type extends TripalField {
    * @see TripalField::widgetForm()
    */
   public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
-
-    $widget = $element;
-    switch ($this->instance['widget']['type']) {
-      case 'tripal_content_type_widget':
-        // There is no widget for this type.
-        break;
-    }
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
+    $widget['value'] = array(
+      '#type' => 'value',
+      '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
+    );
   }
-
 }

+ 20 - 28
tripal/includes/tripal.fields.inc

@@ -236,23 +236,32 @@ function tripal_field_instance_settings_form($field, $instance) {
   return $form;
 }
 /**
- * Implements hook_instance_settings_form_validate().
  *
- * This is not an actual Drpual hook, but rather a Tripal created hook
- * to alow the TripalField objects to have a instanceSettingsFormValidate()
- * member function.
  */
 function tripal_field_instance_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) {
-    $tfield = new $field_type($field, $instance);
-    $form = $tfield->instanceSettingsFormValidate($form, $form_state);
-  }
+  $tfield = new $field_type($field, $instance);
+  $form = $tfield->instanceSettingsFormValidate($form, $form_state);
+}
+
+/**
+ *
+ */
+function tripal_field_widget_form_validate($form, &$form_state) {
+  $entity = $form['#entity'];
+  $entity_type = $form['#entity_type'];
+  $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);
 }
 
+
 /**
  * Implements hook_field_settings_form_validate().
  *
@@ -367,28 +376,11 @@ function tripal_field_validate($entity_type, $entity, $field, $instance,
   $is_loaded = tripal_load_include_field_type($field_type);
   if ($is_loaded) {
     $tfield = new $field_type($field, $instance);
-    $tfield->widgetFormValidate($entity_type, $entity, $langcode, $items, $errors);
-  }
-}
-
-/**
- * Implements hook_field_submit()
- *
- * This is a hook called by the TripalEntityUIController class.
- */
-function tripal_field_submit($entity_type, $entity, $field, $instance,
-    $langcode, &$items, $form, &$form_state) {
-
-  $field_type = $field['type'];
-  $is_loaded = tripal_load_include_field_type($field_type);
-  if ($is_loaded) {
-    $tfield = new $field_type($field, $instance);
-    $form = $tfield->widgetFormSubmit($entity_type, $entity, $langcode, $items, $form, $form_state);
+    $tfield->validate($entity_type, $entity, $langcode,
+        $items, $errors);
   }
 }
 
-
-
 /**
  * Implements hook_form_FORM_ID_alter().
  *

+ 7 - 3
tripal_chado/includes/TripalFields/chado_base__dbxref_id.inc

@@ -42,6 +42,7 @@ class chado_base__dbxref_id extends TripalField {
    * @see TripalField::widgetForm()
    */
   public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
@@ -154,9 +155,10 @@ class chado_base__dbxref_id extends TripalField {
 
 
   /**
-   * @see TripalField::widgetFormValidate()
+   * @see TripalField::validate()
    */
-  public function widgetFormValidate($entity_type, $entity, $field, $items, &$errors) {
+  public function validate($entity_type, $entity, $field, $items, &$errors) {
+
     $field_name = $this->field['field_name'];
     $settings = $this->field['settings'];
     $field_name = $this->field['field_name'];
@@ -203,7 +205,7 @@ class chado_base__dbxref_id extends TripalField {
   /**
    * @see TripalField::widgetFormSubmit()
    */
-  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+  public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
     $field_name = $this->field['field_name'];
     $settings = $this->field['settings'];
     $field_name = $this->field['field_name'];
@@ -211,6 +213,8 @@ class chado_base__dbxref_id extends TripalField {
     $field_table = $this->field['settings']['chado_table'];
     $field_column = $this->field['settings']['chado_column'];
 
+    $items = $form_state['values'][$field_name][$langcode];
+
     // Get the field values.
     foreach ($items as $delta => $values) {
       $fk_val = $values['chado-' . $field_table . '__' . $field_column];

+ 3 - 2
tripal_chado/includes/TripalFields/chado_base__organism_id.inc

@@ -49,6 +49,7 @@ class chado_base__organism_id extends TripalField {
    * @see TripalField::widget()
    */
   public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
     $settings = $this->field['settings'];
     $field_name = $this->field['field_name'];
@@ -79,9 +80,9 @@ class chado_base__organism_id extends TripalField {
   }
 
   /**
-   * @see TripalField::widgetFormValidate()
+   * @see TripalField::validate()
    */
-  public function widgetFormValidate($entity_type, $entity, $field, $items, &$errors) {
+  public function validate($entity_type, $entity, $field, $items, &$errors) {
 
     $settings = $this->field['settings'];
     $field_name = $this->field['field_name'];

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

@@ -41,6 +41,8 @@ class chado_feature__md5checksum  extends TripalField {
    * @see TripalField::widgetForm()
    */
   public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
+
     $settings = $this->field['settings'];
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
@@ -66,7 +68,7 @@ class chado_feature__md5checksum  extends TripalField {
   /**
    * @see TripalField::widgetFormSubmit()
    */
-  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+  public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
     $field = $this->field;
     $settings = $field['settings'];
     $field_name = $field['field_name'];
@@ -74,6 +76,8 @@ class chado_feature__md5checksum  extends TripalField {
     $field_table = $field['settings']['chado_table'];
     $field_column = $field['settings']['chado_column'];
 
+    $items = $form_state['values'][$field_name][$langcode];
+
     // Get the residues so we can calculate teh length.
     $residues = $form_state['values']['feature__residues']['und'][0]['chado-feature__residues'];
 

+ 5 - 1
tripal_chado/includes/TripalFields/chado_feature__residues.inc

@@ -66,6 +66,8 @@ class chado_feature__residues extends TripalField {
    * @see TripalField::widgetForm()
    */
   public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
+
     $settings = $this->field['settings'];
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
@@ -99,7 +101,9 @@ class chado_feature__residues extends TripalField {
   /**
    * @see TripalField::widgetFormSubmit()
    */
-  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+  public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+
+    $items = $form_state['values'][$field_name][$langcode];
 
     // Remove any white spaces.
     $residues = $items[0]['chado-feature__residues'];

+ 3 - 1
tripal_chado/includes/TripalFields/chado_feature__seqlen.inc

@@ -63,12 +63,14 @@ class chado_feature__seqlen extends TripalField {
   /**
    * @see TripalField::widgetFormSubmit()
    */
-  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+  public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
     $field_table = $this->field['settings']['chado_table'];
     $field_column = $this->field['settings']['chado_column'];
 
+    $items = $form_state['values'][$field_name][$langcode];
+
     // Get the residues so we can calculate teh length.
     $residues = $form_state['values']['feature__residues']['und'][0]['chado-feature__residues'];
     // Remove any white spaces.

+ 28 - 27
tripal_chado/includes/TripalFields/chado_linker__contact.inc

@@ -81,6 +81,8 @@ class chado_linker__contact extends TripalField {
    * @see TripalField::widgetForm()
    */
   public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
+
     $entity = $form['#entity'];
     $field_name = $this->field['field_name'];
 
@@ -150,7 +152,7 @@ class chado_linker__contact extends TripalField {
   /**
    * @see TripalField::widgetFormSubmit()
    */
-  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+  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'];
@@ -159,36 +161,35 @@ class chado_linker__contact 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'];
-      $contact_id = $values['chado-' . $table_name . '__contact_id'];
-      $name = $values['name'];
-
-      // If the user provided a name then we want to set the foreign key
-      // value to be the chado_record_id
-      if ($name and !$contact_id) {
-        $contact = chado_generate_var('contact', array('name' => $name));
-        $items[$delta]['chado-' . $table_name . '__contact_id'] = $contact->contact_id;
-      }
-
-      // In the widgetFrom function we automatically add the foreign key
-      // record.  But if the user did not provide a contact we want to take
-      // it out so that the Chado field_storage infrastructure won't try to
-      // write a record.
-      if (!$name and !$contact_id) {
-        $items[$delta]['chado-' . $table_name . '__' . $fkey] = '';
-      }
+    $fkey_value = $form_state['values'][$field_name][$langcode][$delta]['value'];
+    $contact_id = $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__contact_id'];
+    $name = $form_state['values'][$field_name][$langcode][$delta]['name'];
+
+    // If the user provided a name then we want to set the foreign key
+    // value to be the chado_record_id
+    if ($name and !$contact_id) {
+      $contact = chado_generate_var('contact', array('name' => $name));
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__contact_id'] = $contact->contact_id;
+    }
 
-      // If the user removed the contact from the contact_name field
-      // then we want to clear out the rest of the hidden values.
-      // Leave the primary key so the record can be deleted.
-      if (!$name and $contact_id) {
-        $items[$delta]['chado-' . $table_name . '__' . $fkey] = '';
-        $items[$delta]['chado-' . $table_name . '__contact_id'] = '';
-      }
+    // In the widgetForm function we automatically add the foreign key
+    // record.  But if the user did not provide a contact we want to take
+    // it out so that the Chado field_storage infrastructure won't try to
+    // write a record.
+    if (!$name and !$contact_id) {
+      $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__' . $fkey] = '';
     }
+
+    // If the user removed the contact from the contact_name field
+    // then we want to clear out the rest of the hidden values.
+    // Leave the primary key so the record can be deleted.
+    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'] = '';
+    };
   }
 
   /**

+ 4 - 0
tripal_chado/includes/TripalFields/chado_linker__cvterm.inc

@@ -87,6 +87,8 @@ class chado_linker__cvterm extends TripalField {
    * @see TripalField::widgetForm()
    */
   public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
+
 
     $entity = $form['#entity'];
     $field_name = $this->field['field_name'];
@@ -208,6 +210,8 @@ class chado_linker__cvterm extends TripalField {
     $table_name = $element['#table_name'];
     $fkey = $element['#fkey_field'];
 
+    $items = $form_state['values'][$field_name][$langcode];
+
     // 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
     // to validate it as if it were being used in a data entry form.

+ 8 - 3
tripal_chado/includes/TripalFields/chado_linker__cvterm_adder.inc

@@ -36,10 +36,10 @@ class chado_linker__cvterm_adder extends TripalField {
    * @see TripalField::widgetForm()
    */
   public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
-
-    // This field has no value field.  Just a fieldset for adding new annotation types.
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
 
+    // This field has no value field.  Just a fieldset for adding new annotation types.
     $widget['#type'] = 'fieldset';
     $widget['#title'] = $element['#title'];
     $widget['#description'] = $element['#description'];
@@ -82,7 +82,12 @@ class chado_linker__cvterm_adder extends TripalField {
     );
   }
 
-  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+  /**
+   * @see TripalField::widgetFormSubmit()
+   */
+  public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+
+    $items = $form_state['values'][$field_name][$langcode];
 
     // Add the new field to the entity
     if (array_key_exists('triggering_element', $form_state) and

+ 6 - 3
tripal_chado/includes/TripalFields/chado_linker__dbxref.inc

@@ -67,6 +67,7 @@ class chado_linker__dbxref extends TripalField {
    * @see TripalField::widgetForm()
    */
   public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
@@ -198,9 +199,9 @@ class chado_linker__dbxref extends TripalField {
   }
 
   /**
-   * @see TripalField::widgetFormValidate()
+   * @see TripalField::validate()
    */
-  public function widgetFormValidate($entity_type, $entity, $field, $items, &$errors) {
+  public function validate($entity_type, $entity, $field, $items, &$errors) {
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
     $table_name = $this->field['settings']['chado_table'];
@@ -253,7 +254,7 @@ class chado_linker__dbxref extends TripalField {
   /**
    * @see TripalField::widgetFormSubmit()
    */
-  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+  public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
 
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
@@ -266,6 +267,8 @@ class chado_linker__dbxref extends TripalField {
     $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
     $fkey = $fkeys[0];
 
+    $items = $form_state['values'][$field_name][$langcode];
+
     // Get the field values.
     foreach ($items as $delta => $values) {
 

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

@@ -47,6 +47,7 @@ class chado_linker__prop extends TripalField {
    * @see TripalField::widgetForm()
    */
   public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
@@ -122,7 +123,7 @@ class chado_linker__prop extends TripalField {
   /**
    * @see TripalField::validate()
    */
-  public function widgetFormValidate($entity_type, $entity, $field, $items, &$errors) {
+  public function validate($entity_type, $entity, $field, $items, &$errors) {
 /*     $field_name = $this->field['field_name'];
 
     $matches = array();
@@ -169,11 +170,13 @@ class chado_linker__prop extends TripalField {
       chado_delete_record($table_name, $match);
     } */
   }
-  
+
   /**
    * @see TripalField::widgetFormSubmit()
    */
-  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+  public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+
+    $items = $form_state['values'][$field_name][$langcode];
 
     $field_table = $this->field['settings']['chado_table'];
     foreach ($items AS $delta => $item) {
@@ -187,7 +190,7 @@ class chado_linker__prop extends TripalField {
       }
     }
   }
-  
+
   /**
    * @see TripalField::load()
    */

+ 24 - 46
tripal_chado/includes/TripalFields/chado_linker__prop_adder.inc

@@ -36,6 +36,7 @@ class chado_linker__prop_adder extends TripalField {
    * @see TripalField::widgetForm()
    */
   public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
     $field_name = $widget['#field_name'];
 
@@ -56,6 +57,7 @@ class chado_linker__prop_adder extends TripalField {
           In the future, this field will be present for all records
           of this type.'),
     );
+
     $term_name = array_key_exists('values', $form_state) ? $form_state['values'][$field_name]['und'][0]['wrapper']['term_name'] : '';
 
     // Drupal's vertical feild set is a bit quirky in that we can't just
@@ -76,7 +78,6 @@ class chado_linker__prop_adder extends TripalField {
         already be loaded into Tripal.  For example, to create a content
         type for storing 'genes', use the 'gene' term from the
         Sequence Ontology (SO)."),
-      '#required'    => TRUE,
       '#default_value' => $term_name,
       '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/",
     );
@@ -137,7 +138,6 @@ class chado_linker__prop_adder extends TripalField {
           '#title'       => t('Number of Values'),
           '#type'        => 'textfield',
           '#description' => t("The number of values allowed for this property. 0 for unlimited values"),
-          '#required'    => TRUE,
           '#size' => 10,
           '#default_value' => 1,
         );
@@ -152,62 +152,40 @@ class chado_linker__prop_adder extends TripalField {
   }
 
   /**
-   * @see TripalField::widgetFormValidate
+   * @see TripalField::widgetFormValidate()
    */
-  public function widgetFormValidate($entity_type, $entity, $langcode, $items, &$errors) {
-    
-    // We will never have more than one item for this field at a time, so
-    // delta is always zero.
-    $delta = 0;
+  public function widgetFormValidate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+    $field = $this->field;
+    $field_name = $field['field_name'];
 
-    // Get the form values
-    $wrapper = tripal_get_field_item_keyval($items, $delta, 'wrapper', '');
-    $term_name = key_exists('term_name', $wrapper) ? $wrapper['term_name'] : '';
-    $terms_list = key_exists('terms_list', $wrapper) ? $wrapper['terms_list'] : '';
-dpm($term_name);
-    dpm(key($terms_list));
-/*     if ($terms_list) {
-      $num_selection = 0;
-      $cvterm_id = '';
-      foreach ($terms_list AS $key => $val) {
-        if ($val) {
-          $cvterm_id = preg_replace('/^term-/', '', $key);
-          $num_selection ++;
-        }
-      }
-      
-      // Allow only one selection for the term
-      if ($num_selection != 1) {
-        $errors[$this->field['field_name']][$langcode][$delta][] = array(
-          'error' => 'chado_linker__prop_adder',
-          'message' => t("Please select one and only one term."),
-        );
-      }
-      
-      // Do not proceed if the field already exists
-      $base_table = $this->field['settings']['base_table'];
-      $prop_table = $base_table . 'prop';
-      $field_name = $prop_table . '__' . $cvterm_id;
-      // Create an instance of the field.
-      $instance = field_info_instance($entity_type, $field_name,  $entity->bundle);
-      if ($instance) {
-        $errors[$this->field['field_name']][$langcode][$delta][] = array(
-          'error' => 'chado_linker__prop_adder',
-          'message' => t("The property already exists."),
-        );
+    // If the user has clicked the 'user_term_button' then we need to makes
+    // sure that the cardinality textbox contains a positive integer.
+    if ($form_state['triggering_element']['#name'] == 'use_term_button') {
+      $cardinality = $form_state['values'][$field_name][$langcode][$delta]['wrapper']['cardinality'];
+      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.");
       }
-    } */
+    }
+  }
+
+  /**
+   * @see TripalField::widgetFormValidate
+   */
+  public function validate($entity_type, $entity, $field, $items, &$errors) {
+    // Nothing to validate.
   }
 
   /**
    * @see TripalField::widgetFormSubmit()
    */
-  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+  public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
     return;
     // We will never have more than one item for this field at a time, so
     // delta is always zero.
     $delta = 0;
 
+    $items = $form_state['values'][$field_name][$langcode];
+
     // Add the new field to the entity but only if the property adder button
     // was clicked
     if (!array_key_exists('triggering_element', $form_state) or
@@ -295,4 +273,4 @@ function tripal_chado_prop_adder_form_ajax_callback($form, $form_state) {
   // return $form[$field_name]. We have set the AJAX call to replace
   // everything inside of the 'wrapper' element, so we must return that.
   return $form[$field_name]['und'][0]['wrapper'];
-}
+}

+ 5 - 1
tripal_chado/includes/TripalFields/chado_linker__pub.inc

@@ -58,6 +58,7 @@ class chado_linker__pub extends TripalField {
    * @see TripalField::widgetForm()
    */
   public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
     $entity = $form['#entity'];
     $field_name = $this->field['field_name'];
@@ -128,7 +129,8 @@ class chado_linker__pub extends TripalField {
   /**
    * @see TripalField::widgetFormSubmit()
    */
-  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+  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'];
@@ -138,6 +140,8 @@ class chado_linker__pub extends TripalField {
     $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
     $fkey = $fkeys[0];
 
+    $items = $form_state['values'][$field_name][$langcode];
+
     // Get the field values.
     foreach ($items as $delta => $values) {
       $fkey_value = $values['value'];

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

@@ -118,6 +118,7 @@ class chado_linker__relationship extends TripalField {
    * @see TripalField::widgetForm()
    */
   public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
@@ -156,7 +157,7 @@ class chado_linker__relationship extends TripalField {
     $object_uniquename = '';
     $value = '';
     $rank = '';
-    
+
     // Handle special cases
     $subject_id_key = 'subject_id';
     $object_id_key = 'object_id';
@@ -424,7 +425,7 @@ class chado_linker__relationship extends TripalField {
   /**
    * @see TripalField::validate()
    */
-  function widgetFormValidate($entity_type, $entity, $langcode, $items, &$errors) {
+  function validate($entity_type, $entity, $langcode, $items, &$errors) {
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
     $field_table = $this->field['settings']['chado_table'];
@@ -449,7 +450,7 @@ class chado_linker__relationship extends TripalField {
       $subject_id_key = 'subject_project_id';
       $object_id_key = 'object_project_id';
     }
-    
+
     foreach ($items as $delta => $item) {
       $subject_id = $item[$field_table . '__' . $subject_id_key];
       $object_id = $item[ $field_table . '__' . $object_id_key];
@@ -583,16 +584,17 @@ class chado_linker__relationship extends TripalField {
   /**
    * @see TripalField::submit()
    */
-  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+  public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
 return;
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
     $field_table = $this->field['settings']['chado_table'];
     $field_column = $this->field['settings']['chado_column'];
     $base_table = $this->field['settings']['base_table'];
-
     $chado_record_id = $entity->chado_record_id;
 
+    $items = $form_state['values'][$field_name][$langcode];
+
     $schema = chado_get_schema($field_table);
     $fkeys = $schema['foreign keys'];
 

+ 6 - 3
tripal_chado/includes/TripalFields/chado_linker__synonym.inc

@@ -48,6 +48,7 @@ class chado_linker__synonym extends TripalField {
    * @see TripalField::widgetForm()
    */
   public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
     $entity = $form['#entity'];
     $field_name = $this->field['field_name'];
@@ -158,9 +159,9 @@ class chado_linker__synonym extends TripalField {
   }
 
   /**
-   * @see TripalField::widgetFormValidate()
+   * @see TripalField::validate()
    */
-  public function widgetFormValidate($entity_type, $entity, $field, $items, &$errors) {
+  public function validate($entity_type, $entity, $field, $items, &$errors) {
 
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
@@ -206,7 +207,7 @@ class chado_linker__synonym extends TripalField {
   /**
    * @see TripalField::widgetFormSubmit()
    */
-  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+  public function widgetFormSubmit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
     $table_name = $this->field['settings']['chado_table'];
@@ -218,6 +219,8 @@ class chado_linker__synonym extends TripalField {
     $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
     $fkey = $fkeys[0];
 
+    $items = $form_state['values'][$field_name][$langcode];
+
     // Get the field values.
     foreach ($items as $delta => $values) {
 

+ 1 - 0
tripal_chado/includes/TripalFields/chado_organism__type_id.inc

@@ -27,6 +27,7 @@ class chado_organism__type_id extends TripalField {
    * @see TripalField::widget()
    */
   public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::widgetForm($widget, $form, $form_state, $langcode, $items, $delta, $element);
 
     $settings = $this->field['settings'];
     $field_name = $this->field['field_name'];

+ 1 - 2
tripal_chado/includes/tripal_chado.migrate.inc

@@ -605,14 +605,13 @@ function tripal_chado_migrate_map_types($tv2_content_types) {
  * @param unknown $tv3_content_type
  */
 function tripal_chado_migrate_selected_types($tv3_content_types) {
-  
+
   // Initialize the population of the tripal_cvterm_mapping table before migration.
   tripal_chado_map_cvterms();
 
   foreach ($tv3_content_types AS $tv3_content_type) {
     // Check if the term already exists
     $term = tripal_load_term_entity($tv3_content_type);
-dpm($tv3_content_type);
     // If term doesn't exist, create a new bundle for this term
     if (!$term) {
       print("Creating bundle for term '" . $tv3_content_type['term_name'] . "'...\n");