Przeglądaj źródła

Moved validate function within the field class

Chun-Huai Cheng 8 lat temu
rodzic
commit
8fcd0cf1ab

+ 21 - 28
tripal_chado/includes/TripalFields/chado_base__organism_id.inc

@@ -78,6 +78,27 @@ class chado_base__organism_id extends TripalField {
 //      '#element_validate' => array('chado_base__organism_id_widget_validate'),
     );
   }
+  
+  public function widgetFormValidate($entity_type, $entity, $field, $items, &$errors) {
+
+    $settings = $field['settings'];
+    $field_name = $field['field_name'];
+    $field_type = $field['type'];
+    $field_table = $field['settings']['chado_table'];
+    $field_column = $field['settings']['chado_column'];
+    
+    // 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.
+    if ($form_state['build_info']['form_id'] =='field_ui_field_edit_form') {
+      return;
+    }
+    //$organism_id = tripal_chado_get_field_form_values($field_name, $form_state, 0, $field_table . '__organism_id');
+    
+    if (!$organism_id) {
+      form_error($element, t("Please specify an organism."));
+    }
+  }
 
   /**
    * @see TripalField::load()
@@ -208,32 +229,4 @@ class chado_base__organism_id extends TripalField {
     return $element;
   }
 
-}
-
-
-/**
- * Callback function for validating the chado_base__organism_id_widget.
- */
-function chado_base__organism_id_widget_validate($element, &$form_state) {
-  $field_name = $element['#parents'][0];
-  $field = $form_state['field'][$field_name]['und']['field'];
-  $settings = $field['settings'];
-  $field_name = $field['field_name'];
-  $field_type = $field['type'];
-  $field_table = $field['settings']['chado_table'];
-  $field_column = $field['settings']['chado_column'];
-
-  // 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.
-  if ($form_state['build_info']['form_id'] =='field_ui_field_edit_form') {
-    return;
-  }
-  //$organism_id = tripal_chado_get_field_form_values($field_name, $form_state, 0, $field_table . '__organism_id');
-
-  if (!$organism_id) {
-    form_error($element, t("Please specify an organism."));
-  }
-
-
 }

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

@@ -67,29 +67,25 @@ class chado_feature__md5checksum  extends TripalField {
     );
   }
 
-}
-
-/**
- * Callback function for validating the chado_feature__md5checksum_widget.
- */
-function chado_feature__md5checksum_widget_validate($element, &$form_state) {
-  $field_name = $element['#parents'][0];
-  $field = $form_state['field'][$field_name]['und']['field'];
-  $settings = $field['settings'];
-  $field_name = $field['field_name'];
-  $field_type = $field['type'];
-  $field_table = $field['settings']['chado_table'];
-  $field_column = $field['settings']['chado_column'];
-
-  // Calculate the md5 checksum for the sequence only if md5 box is checked and
-  // the residues exist.
-  //$residues = tripal_chado_get_field_form_values('feature__residues', $form_state, 0, 'feature__residues');
-  if ($residues) {
-    $residues = preg_replace('/\s/', '', $residues);
-    tripal_chado_set_field_form_values($field_name, $form_state, md5($residues), 0, 'feature__md5checksum');
-  }
-  else {
-    // Otherwise, remove the md5 value
-    tripal_chado_set_field_form_values($field_name, $form_state, '__NULL__', 0, $field_table . '__md5checksum');
+  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+    $field = $this->field;
+    $settings = $field['settings'];
+    $field_name = $field['field_name'];
+    $field_type = $field['type'];
+    $field_table = $field['settings']['chado_table'];
+    $field_column = $field['settings']['chado_column'];
+    
+    // Calculate the md5 checksum for the sequence only if md5 box is checked and
+    // the residues exist.
+    //$residues = tripal_chado_get_field_form_values('feature__residues', $form_state, 0, 'feature__residues');
+    if ($residues) {
+      $residues = preg_replace('/\s/', '', $residues);
+      tripal_chado_set_field_form_values($field_name, $form_state, md5($residues), 0, 'feature__md5checksum');
+    }
+    else {
+      // Otherwise, remove the md5 value
+      tripal_chado_set_field_form_values($field_name, $form_state, '__NULL__', 0, $field_table . '__md5checksum');
+    }
   }
-}
+  
+}

+ 10 - 7
tripal_chado/includes/TripalFields/chado_feature__residues.inc

@@ -96,6 +96,16 @@ class chado_feature__residues extends TripalField {
       '#cols' => 30,
     );
   }
+  
+  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+
+    // Remove any white spaces.
+    //$residues = tripal_chado_get_field_form_values($field_name, $form_state, 0, 'feature__residues');
+    if ($residues) {
+      $residues = preg_replace('/\s/', '', $residues);
+      tripal_chado_set_field_form_values($field_name, $form_state, $residues, 0, 'feature__residues');
+    }
+  }
 
   /**
    * @see TripalField::load()
@@ -567,14 +577,7 @@ class chado_feature__residues extends TripalField {
  * Callback function for validating the chado_feature__residues_widget.
  */
 function chado_feature__residues_widget_validate($element, &$form_state) {
-  $field_name = $element['#parents'][0];
 
-  // Remove any white spaces.
-  //$residues = tripal_chado_get_field_form_values($field_name, $form_state, 0, 'feature__residues');
-  if ($residues) {
-    $residues = preg_replace('/\s/', '', $residues);
-    tripal_chado_set_field_form_values($field_name, $form_state, $residues, 0, 'feature__residues');
-  }
 }
 
 /**

+ 14 - 19
tripal_chado/includes/TripalFields/chado_feature__seqlen.inc

@@ -61,24 +61,19 @@ class chado_feature__seqlen extends TripalField {
 //      '#element_validate' => array('chado_feature__seqlen_widget_validate'),
     );
   }
-
-}
-
-/**
- * Callback function for validating the chado_feature__seqlen_widget.
- */
-function chado_feature__seqlen_widget_validate($element, &$form_state) {
-  $field_name = $element['#parents'][0];
-
-  // Get the residues so we can calculate teh length.
-  //$residues = tripal_chado_get_field_form_values('feature__residues', $form_state, 0, 'feature__residues');
-  // Remove any white spaces.
-  if ($residues) {
-    $residues = preg_replace('/\s/', '', $residues);
-    tripal_chado_set_field_form_values($field_name, $form_state, strlen($residues), 0, 'feature__seqlen');
-  }
-  else {
-    // Otherwise, remove the seqlen value
-    tripal_chado_set_field_form_values($field_name, $form_state, '__NULL__', 0, 'feature_seqlen');
+  
+  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+    // Get the residues so we can calculate teh length.
+    //$residues = tripal_chado_get_field_form_values('feature__residues', $form_state, 0, 'feature__residues');
+    // Remove any white spaces.
+    if ($residues) {
+      $residues = preg_replace('/\s/', '', $residues);
+      tripal_chado_set_field_form_values($field_name, $form_state, strlen($residues), 0, 'feature__seqlen');
+    }
+    else {
+      // Otherwise, remove the seqlen value
+      tripal_chado_set_field_form_values($field_name, $form_state, '__NULL__', 0, 'feature_seqlen');
+    }
   }
+
 }

+ 46 - 48
tripal_chado/includes/TripalFields/chado_linker__cvterm.inc

@@ -199,6 +199,52 @@ class chado_linker__cvterm extends TripalField {
     );
 
   }
+  
+  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+
+    $field_name = $element['#field_name'];
+    $delta = $element['#delta'];
+    $table_name = $element['#table_name'];
+    $fkey = $element['#fkey_field'];
+    
+    // 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.
+    if ($form_state['build_info']['form_id'] =='field_ui_field_edit_form') {
+      return;
+    }
+    
+    // Get the field values.
+    //   $cvterm_id = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $table_name . '__cvterm_id');
+    //   $cv_id = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $table_name . '--cvterm__cv_id--cv__cv_id');
+    //   $cvterm_name = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $table_name . '--cvterm__name');
+    //   $cvterm_id = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $table_name . '__cvterm_id');
+    //   $pub_id = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $table_name . '__pub_id');
+    
+    // If the user provided a cv_id and a name then we want to set the
+    // foreign key value to be the chado_record_idd
+    if ($cvterm_name) {
+    
+      $fkey_value = $element['#entity']->chado_record_id;
+      tripal_chado_set_field_form_values($field_name, $form_state, $fkey_value, $delta, $table_name . '__' . $fkey);
+    
+      // Get the cvterm ID. If one is not available because it's a newly added
+      // record, then we need to retrieve it and set the form element.
+      if (!$cvterm_id) {
+        $cvterm = tripal_get_cvterm(array('cv_id' => $cv_id, 'name' => $cvterm_name));
+        tripal_chado_set_field_form_values($field_name, $form_state, $cvterm->cvterm_id, $delta, $table_name . '__cvterm_id');
+      }
+    
+      if (!$pub_id) {
+        $pub = chado_generate_var('pub', array('uniquename' => 'null'));
+        tripal_chado_set_field_form_values($field_name, $form_state, $pub->pub_id, $delta, $table_name . '__pub_id');
+      }
+    }
+    else {
+      // If the $cv_id and name are not set, then remove the linker FK value to the base table.
+      tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__' . $fkey);
+    }
+  }
 
   /**
    * @see TripalField::load()
@@ -305,55 +351,7 @@ function theme_chado_linker__cvterm_widget($variables) {
 
   return $layout;
 }
-/**
- * Callback function for validating the chado_linker__cvterm_widget.
- */
-function chado_linker__cvterm_widget_validate($element, &$form_state) {
-
-  $field_name = $element['#field_name'];
-  $delta = $element['#delta'];
-  $table_name = $element['#table_name'];
-  $fkey = $element['#fkey_field'];
 
-  // 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.
-  if ($form_state['build_info']['form_id'] =='field_ui_field_edit_form') {
-    return;
-  }
-
-  // Get the field values.
-//   $cvterm_id = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $table_name . '__cvterm_id');
-//   $cv_id = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $table_name . '--cvterm__cv_id--cv__cv_id');
-//   $cvterm_name = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $table_name . '--cvterm__name');
-//   $cvterm_id = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $table_name . '__cvterm_id');
-//   $pub_id = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $table_name . '__pub_id');
-
-  // If the user provided a cv_id and a name then we want to set the
-  // foreign key value to be the chado_record_idd
-  if ($cvterm_name) {
-
-    $fkey_value = $element['#entity']->chado_record_id;
-    tripal_chado_set_field_form_values($field_name, $form_state, $fkey_value, $delta, $table_name . '__' . $fkey);
-
-    // Get the cvterm ID. If one is not available because it's a newly added
-    // record, then we need to retrieve it and set the form element.
-    if (!$cvterm_id) {
-      $cvterm = tripal_get_cvterm(array('cv_id' => $cv_id, 'name' => $cvterm_name));
-      tripal_chado_set_field_form_values($field_name, $form_state, $cvterm->cvterm_id, $delta, $table_name . '__cvterm_id');
-    }
-
-    if (!$pub_id) {
-      $pub = chado_generate_var('pub', array('uniquename' => 'null'));
-      tripal_chado_set_field_form_values($field_name, $form_state, $pub->pub_id, $delta, $table_name . '__pub_id');
-    }
-  }
-  else {
-    // If the $cv_id and name are not set, then remove the linker FK value to the base table.
-    tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__' . $fkey);
-  }
-
-}
 /**
  * An Ajax callback for the dbxref widget.
  */

+ 82 - 84
tripal_chado/includes/TripalFields/chado_linker__cvterm_adder.inc

@@ -73,89 +73,87 @@ class chado_linker__cvterm_adder extends TripalField {
       '#limit_validation_errors' => array(array($this->field['field_name'])),
     );
   }
-
-}
-/**
- * Callback function for validating the chado_linker__cvterm_adder_widget.
- */
-function chado_linker__cvterm_adder_widget_validate($element, &$form_state) {
-
-  // Add the new field to the entity
-  if (array_key_exists('triggering_element', $form_state) and
-      $form_state['triggering_element']['#name'] == 'cvterm_class_adder_button') {
-
-    $form_state['rebuild'] = TRUE;
-    $field_name = $element['#field_name'];
-    $entity_type = $element['#entity']->type;
-    $bundle = $element['#entity']->bundle;
-
-    // Get the base table name from the field annotations.
-    $field = field_info_field($field_name);
-    $base_table = $field['settings']['base_table'];
-
-    // Get the vocabulary.
-    //$cvterm_class_adder = tripal_chado_get_field_form_values($field_name, $form_state);
-    $cv = chado_generate_var('cv', array('cv_id' => $cvterm_class_adder));
-
-    if (!$cv) {
-      form_set_error(implode('][', $element ['#parents']) . '][value', t("Please select a vocabulary."));
-      return;
-    }
-
-    $type_field_name = $field_name . '__' . $cv->cv_id;
-
-    // The field name is the table name in this case. We want to get the
-    // primary key as this should be the field that maps th the value.
-    $schema = chado_get_schema($field_name);
-    $pkey = $schema['primary key'][0];
-
-    // Add the field if it doesn't already exists.
-    $field = field_info_field('cvterm');
-    if (!$field) {
-      $create_info = array(
-        'field_name' => 'cvterm',
-        'type' => 'tripal_chado_cvterm_widget',
-        'cardinality' => FIELD_CARDINALITY_UNLIMITED,
-        'locked' => FALSE,
-        'storage' => array(
-          'type' => 'field_chado_storage',
-        ),
-        'settings' => array(
-          'chado_table' => $field_name,
-          'chado_column' => $pkey,
-          'base_table' => $base_table,
-        ),
-      );
-      $field = field_create_field($create_info);
-    }
-
-    // Attach the field to the bundle if it isn't already.
-    if (!$field or !array_key_exists('bundles', $field) or
-        !array_key_exists('TripalEntity', $field['bundles']) or
-        !in_array($bundle_name, $field['bundles']['TripalEntity'])) {
-      $createInstanceInfo = array(
-        'field_name' => 'cvtmerm',
-        'entity_type' => 'TripalEntity',
-        'bundle' => $this->bundle->name,
-        'label' => ucfirst(preg_replace('/_/', ' ', $cv->name)),
-        'description' => "Annotations from the $cv->name vocabulary",
-        'required' => FALSE,
-        'settings' => array(),
-        'widget' => array(
-          'type' => 'tripal_chado_cvterm_widget',
-          'settings' => array(
-            'display_label' => 1,
-          ),
-        ),
-        'display' => array(
-          'default' => array(
-            'label' => 'above',
-            'type' => 'tripal_chado_cvterm_formatter',
-            'settings' => array(),
-          ),
-        ),
-      );
-      $instance = field_create_instance($createInstanceInfo);
-    }
+  
+  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+
+    // Add the new field to the entity
+    if (array_key_exists('triggering_element', $form_state) and
+        $form_state['triggering_element']['#name'] == 'cvterm_class_adder_button') {
+    
+          $form_state['rebuild'] = TRUE;
+          $field_name = $element['#field_name'];
+          $entity_type = $element['#entity']->type;
+          $bundle = $element['#entity']->bundle;
+    
+          // Get the base table name from the field annotations.
+          $field = field_info_field($field_name);
+          $base_table = $field['settings']['base_table'];
+    
+          // Get the vocabulary.
+          //$cvterm_class_adder = tripal_chado_get_field_form_values($field_name, $form_state);
+          $cv = chado_generate_var('cv', array('cv_id' => $cvterm_class_adder));
+    
+          if (!$cv) {
+            form_set_error(implode('][', $element ['#parents']) . '][value', t("Please select a vocabulary."));
+            return;
+          }
+    
+          $type_field_name = $field_name . '__' . $cv->cv_id;
+    
+          // The field name is the table name in this case. We want to get the
+          // primary key as this should be the field that maps th the value.
+          $schema = chado_get_schema($field_name);
+          $pkey = $schema['primary key'][0];
+    
+          // Add the field if it doesn't already exists.
+          $field = field_info_field('cvterm');
+          if (!$field) {
+            $create_info = array(
+              'field_name' => 'cvterm',
+              'type' => 'tripal_chado_cvterm_widget',
+              'cardinality' => FIELD_CARDINALITY_UNLIMITED,
+              'locked' => FALSE,
+              'storage' => array(
+                'type' => 'field_chado_storage',
+              ),
+              'settings' => array(
+                'chado_table' => $field_name,
+                'chado_column' => $pkey,
+                'base_table' => $base_table,
+              ),
+            );
+            $field = field_create_field($create_info);
+          }
+    
+          // Attach the field to the bundle if it isn't already.
+          if (!$field or !array_key_exists('bundles', $field) or
+              !array_key_exists('TripalEntity', $field['bundles']) or
+              !in_array($bundle_name, $field['bundles']['TripalEntity'])) {
+                $createInstanceInfo = array(
+                  'field_name' => 'cvtmerm',
+                  'entity_type' => 'TripalEntity',
+                  'bundle' => $this->bundle->name,
+                  'label' => ucfirst(preg_replace('/_/', ' ', $cv->name)),
+                  'description' => "Annotations from the $cv->name vocabulary",
+                  'required' => FALSE,
+                  'settings' => array(),
+                  'widget' => array(
+                    'type' => 'tripal_chado_cvterm_widget',
+                    'settings' => array(
+                      'display_label' => 1,
+                    ),
+                  ),
+                  'display' => array(
+                    'default' => array(
+                      'label' => 'above',
+                      'type' => 'tripal_chado_cvterm_formatter',
+                      'settings' => array(),
+                    ),
+                  ),
+                );
+                $instance = field_create_instance($createInstanceInfo);
+              }
+        }
   }
+
 }

+ 58 - 61
tripal_chado/includes/TripalFields/chado_linker__dbxref.inc

@@ -195,6 +195,64 @@ class chado_linker__dbxref extends TripalField {
     }
   }
 
+  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+
+    $field_name = $element['#field_name'];
+    $delta = $element['#delta'];
+    $table_name = $element['#table_name'];
+    $fkey = $element['#fkey_field'];
+    $field = field_info_field($field_name);
+    $field_type = $field['type'];
+    $field_table = $field['settings']['chado_table'];
+    $field_column = $field['settings']['chado_column'];
+    $field_prefix = $field_table . '__dbxref_id';
+    
+    // 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.
+    if ($form_state['build_info']['form_id'] =='field_ui_field_edit_form') {
+      return;
+    }
+    
+    // Get the field values.
+    //   $dbxref_id = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $field_table . '__dbxref_id');
+    //   $db_id = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $field_prefix . '--db_id');
+    //   $accession = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $field_prefix . '--accession');
+    //   $version = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $field_prefix . '--version');
+    //   $description = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $field_prefix . '--description');
+    
+    // Make sure that if a database ID is provided that an accession is also
+    // provided.  Here we use the form_set_error function rather than the
+    // form_error function because the form_error will add a red_highlight
+    // around all of the fields in the fieldset which is confusing as it's not
+    // clear to the user what field is required and which isn't. Therefore,
+    // we borrow the code from the 'form_error' function and append the field
+    // so that the proper field is highlighted on error.
+    if (!$db_id and $accession) {
+      form_set_error(implode('][', $element ['#parents']) . '][' . $field_prefix . '--db_id', t("A database and the accession must both be provided."));
+    }
+    if ($db_id and !$accession) {
+      form_set_error(implode('][', $element ['#parents']) . '][' . $field_prefix . '--accession', t("A database and the accession must both be provided."));
+    }
+    if (!$db_id and !$accession and ($version or $description)) {
+      form_set_error(implode('][', $element ['#parents']) . '][' . $field_prefix . '--db_id', t("A database and the accession must both be provided."));
+    }
+    
+    // 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) {
+        tripal_chado_set_field_form_values($field_name, $form_state, $dbxref->dbxref_id, $delta, $table_name . '__dbxref_id');
+        tripal_chado_set_field_form_values($field_name, $form_state, $dbxref->dbxref_id, $delta, $field_prefix . '--dbxref_id');
+      }
+    }
+    else {
+      // If the db_id and accession are not set, then remove the linker FK value to the base table.
+      tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__' . $fkey);
+    }
+  }
   /**
    * @see TripalField::load()
    */
@@ -287,67 +345,6 @@ function theme_chado_linker__dbxref_widget($variables) {
 
   return $layout;
 }
-/**
- * Callback function for validating the chado_linker__dbxref_widget.
- */
-function chado_linker__dbxref_widget_validate($element, &$form_state) {
-
-  $field_name = $element['#field_name'];
-  $delta = $element['#delta'];
-  $table_name = $element['#table_name'];
-  $fkey = $element['#fkey_field'];
-  $field = field_info_field($field_name);
-  $field_type = $field['type'];
-  $field_table = $field['settings']['chado_table'];
-  $field_column = $field['settings']['chado_column'];
-  $field_prefix = $field_table . '__dbxref_id';
-
-  // 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.
-  if ($form_state['build_info']['form_id'] =='field_ui_field_edit_form') {
-    return;
-  }
-
-  // Get the field values.
-//   $dbxref_id = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $field_table . '__dbxref_id');
-//   $db_id = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $field_prefix . '--db_id');
-//   $accession = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $field_prefix . '--accession');
-//   $version = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $field_prefix . '--version');
-//   $description = tripal_chado_get_field_form_values($field_name, $form_state, $delta, $field_prefix . '--description');
-
-  // Make sure that if a database ID is provided that an accession is also
-  // provided.  Here we use the form_set_error function rather than the
-  // form_error function because the form_error will add a red_highlight
-  // around all of the fields in the fieldset which is confusing as it's not
-  // clear to the user what field is required and which isn't. Therefore,
-  // we borrow the code from the 'form_error' function and append the field
-  // so that the proper field is highlighted on error.
-  if (!$db_id and $accession) {
-    form_set_error(implode('][', $element ['#parents']) . '][' . $field_prefix . '--db_id', t("A database and the accession must both be provided."));
-  }
-  if ($db_id and !$accession) {
-    form_set_error(implode('][', $element ['#parents']) . '][' . $field_prefix . '--accession', t("A database and the accession must both be provided."));
-  }
-  if (!$db_id and !$accession and ($version or $description)) {
-    form_set_error(implode('][', $element ['#parents']) . '][' . $field_prefix . '--db_id', t("A database and the accession must both be provided."));
-  }
-
-  // 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) {
-      tripal_chado_set_field_form_values($field_name, $form_state, $dbxref->dbxref_id, $delta, $table_name . '__dbxref_id');
-      tripal_chado_set_field_form_values($field_name, $form_state, $dbxref->dbxref_id, $delta, $field_prefix . '--dbxref_id');
-    }
-  }
-  else {
-    // If the db_id and accession are not set, then remove the linker FK value to the base table.
-    tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__' . $fkey);
-  }
-}
 
 /**
  * An Ajax callback for the dbxref widget.

+ 0 - 13
tripal_chado/includes/TripalFields/chado_linker__featureloc.inc

@@ -304,17 +304,4 @@ class chado_linker__featureloc extends TripalField {
   }
 
 }
-/**
- * Callback function for validating the chado_linker_featureloc_widget.
- */
-function chado_linker__featureloc_widget_validate($element, &$form_state) {
-
-}
-/**
- * Validation function for the chado_linker_featureloc_formatter_settings_form.
- */
-function chado_linker__featureloc_formatter_settings_form_validate(&$form, &$form_state) {
-
-  // Place here as an example for validating the settings form.
-}
 

+ 83 - 84
tripal_chado/includes/TripalFields/chado_linker__prop_adder.inc

@@ -74,93 +74,92 @@ class chado_linker__prop_adder extends TripalField {
   public function widgetFormValidate($entity_type, $entity, $field, $items, &$errors) {
 
   }
-}
-/**
- * Callback function for validating the chado_linker__prop_adder_widget.
- */
-function chado_linker__prop_adder_widget_validate($element, &$form_state) {
+  
+  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
 
-  // Add the new field to the entity
-  if (array_key_exists('triggering_element', $form_state) and
+    // Add the new field to the entity
+    if (array_key_exists('triggering_element', $form_state) and
       $form_state['triggering_element']['#name'] == 'kvproperty_adder_button') {
 
-        $form_state['rebuild'] = TRUE;
-        $field_name = $element['#field_name'];
-        $entity_type = $element['#entity']->type;
-        $bundle = $element['#entity']->bundle;
-
-        // Get the base table name from the field properties.
-        $field = field_info_field($field_name);
-        $base_table = $field['settings']['base_table'];
-
-        // Get the term for the property
-        //$kvproperty = tripal_chado_get_field_form_values($field_name, $form_state);
-        $term = chado_generate_var('cvterm', array('name' => $kvproperty), $options = array('return_array' => TRUE));
-
-        if (count($term) == 1) {
-          $prop_field_name = $field_name . '__' . $term[0]->cvterm_id;
-
-          // The field name is the table name in this case. We want to get the
-          // primary key as this should be the field that maps th the value.
-          $schema = chado_get_schema($field_name);
-          $pkey = $schema['primary key'][0];
-
-          // Add the field if it doesn't already exists.
-          $field = field_info_field('cvterm');
-          if (!$field) {
-            $create_info = array(
-              'field_name' => 'property-' . $term[0]->cvterm_id,
-              'type' => 'tripal_chado_kvproperty_widget',
-              'cardinality' => FIELD_CARDINALITY_UNLIMITED,
-              'locked' => FALSE,
-              'storage' => array(
-                'type' => 'field_chado_storage',
-              ),
-              'settings' => array(
-                'chado_table' => $field_name,
-                'chado_column' => $pkey,
-                'base_table' => $base_table,
-                'semantic_web' => '',
-              ),
-            );
-            $field = field_create_field($create_info);
-          }
-
-          // Attach the field to the bundle if it isn't already.
-          if (!$field and array_key_exists('bundles', $field) or
-              !array_key_exists('TripalEntity', $field['bundles']) or
-              !in_array($bundle_name, $field['bundles']['TripalEntity'])) {
-
-            $createInstanceInfo = array(
-              'field_name' => 'property-' . $term[0]->cvterm_id,
-              'entity_type' => 'TripalEntity',
-              'bundle' => $this->bundle->name,
-              'label' => ucfirst(preg_replace('/_/', ' ', $term[0]->name)),
-              'description' => $term[0]->definition ? $term[0]->definition : '',
-              'required' => FALSE,
-              'settings' => array(),
-              'widget' => array(
-                'type' => 'tripal_chado_kvproperty_widget',
-                'settings' => array(
-                  'display_label' => 1,
+      $form_state['rebuild'] = TRUE;
+      $field_name = $element['#field_name'];
+      $entity_type = $element['#entity']->type;
+      $bundle = $element['#entity']->bundle;
+
+      // Get the base table name from the field properties.
+      $field = field_info_field($field_name);
+      $base_table = $field['settings']['base_table'];
+
+      // Get the term for the property
+      //$kvproperty = tripal_chado_get_field_form_values($field_name, $form_state);
+      $term = chado_generate_var('cvterm', array('name' => $kvproperty), $options = array('return_array' => TRUE));
+
+      if (count($term) == 1) {
+        $prop_field_name = $field_name . '__' . $term[0]->cvterm_id;
+
+        // The field name is the table name in this case. We want to get the
+        // primary key as this should be the field that maps th the value.
+        $schema = chado_get_schema($field_name);
+        $pkey = $schema['primary key'][0];
+
+        // Add the field if it doesn't already exists.
+        $field = field_info_field('cvterm');
+        if (!$field) {
+          $create_info = array(
+            'field_name' => 'property-' . $term[0]->cvterm_id,
+            'type' => 'tripal_chado_kvproperty_widget',
+            'cardinality' => FIELD_CARDINALITY_UNLIMITED,
+            'locked' => FALSE,
+            'storage' => array(
+              'type' => 'field_chado_storage',
+            ),
+            'settings' => array(
+              'chado_table' => $field_name,
+              'chado_column' => $pkey,
+              'base_table' => $base_table,
+              'semantic_web' => '',
+            ),
+          );
+          $field = field_create_field($create_info);
+        }
+
+        // Attach the field to the bundle if it isn't already.
+        if (!$field and array_key_exists('bundles', $field) or
+            !array_key_exists('TripalEntity', $field['bundles']) or
+            !in_array($bundle_name, $field['bundles']['TripalEntity'])) {
+
+              $createInstanceInfo = array(
+                'field_name' => 'property-' . $term[0]->cvterm_id,
+                'entity_type' => 'TripalEntity',
+                'bundle' => $this->bundle->name,
+                'label' => ucfirst(preg_replace('/_/', ' ', $term[0]->name)),
+                'description' => $term[0]->definition ? $term[0]->definition : '',
+                'required' => FALSE,
+                'settings' => array(),
+                'widget' => array(
+                  'type' => 'tripal_chado_kvproperty_widget',
+                  'settings' => array(
+                    'display_label' => 1,
+                  ),
                 ),
-              ),
-              'display' => array(
-                'default' => array(
-                  'label' => 'inline',
-                  'type' => 'tripal_chado_kvproperty_formatter',
-                  'settings' => array(),
+                'display' => array(
+                  'default' => array(
+                    'label' => 'inline',
+                    'type' => 'tripal_chado_kvproperty_formatter',
+                    'settings' => array(),
+                  ),
                 ),
-              ),
-            );
-            $instance = field_create_instance($createInstanceInfo);
-          }
-        }
-        else if (count($term) > 1) {
-          form_set_error(implode('][', $element ['#parents']) . '][value', t("This term is present in multiple vocabularies. Please select the appropriate one."));
-        }
-        else {
-          form_set_error(implode('][', $element ['#parents']) . '][value', t("Please provide a property type to add."));
-        }
+              );
+              $instance = field_create_instance($createInstanceInfo);
+            }
+      }
+      else if (count($term) > 1) {
+        form_set_error(implode('][', $element ['#parents']) . '][value', t("This term is present in multiple vocabularies. Please select the appropriate one."));
+      }
+      else {
+        form_set_error(implode('][', $element ['#parents']) . '][value', t("Please provide a property type to add."));
       }
-}
+    }
+  }
+  
+}

+ 40 - 44
tripal_chado/includes/TripalFields/chado_linker__pub.inc

@@ -135,6 +135,46 @@ class chado_linker__pub extends TripalField {
     );
   }
 
+  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+
+    $field_name = $element['#field_name'];
+    $delta = $element['#delta'];
+    $table_name = $element['#table_name'];
+    $fkey = $element['#fkey_field'];
+    
+    // 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.
+    if ($form_state['build_info']['form_id'] =='field_ui_field_edit_form') {
+      return;
+    }
+    
+    // Get the field values.
+    //   $fkey_value = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__' . $fkey);
+    //   $pub_id = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__pub_id');
+    //   $uname = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '--pub__uniquename');
+    
+    // If the user provided a uniquename then we want to set the
+    // foreign key value to be the chado_record_idd
+    if ($uname) {
+    
+      // Get the pub. If one with the same name and type is already present
+      // then use that. Otherwise, insert a new one.
+      if (!$pub_id) {
+        $pub = chado_generate_var('pub', array('uniquename' => $uname));
+        // Set the pub_id and FK value
+        tripal_chado_set_field_form_values($field_name, $form_state, $pub->pub_id, $delta, $table_name . '__pub_id');
+        $fkey_value = $element['#entity']->chado_record_id;
+        tripal_chado_set_field_form_values($field_name, $form_state, $fkey_value, $delta, $table_name . '__' . $fkey);
+      }
+    
+    }
+    else {
+      // If the $syn_name is not set, then remove the linker FK value to the base table.
+      tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__' . $fkey);
+      tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__pub_id');
+    }
+  }
   /**
    * @see TripalField::load()
    */
@@ -192,50 +232,6 @@ class chado_linker__pub extends TripalField {
   }
 }
 
-/**
- * Callback function for validating the chado_linker__pub_widget.
- */
-function chado_linker__pub_widget_validate($element, &$form_state) {
-
-  $field_name = $element['#field_name'];
-  $delta = $element['#delta'];
-  $table_name = $element['#table_name'];
-  $fkey = $element['#fkey_field'];
-
-  // 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.
-  if ($form_state['build_info']['form_id'] =='field_ui_field_edit_form') {
-    return;
-  }
-
-  // Get the field values.
-//   $fkey_value = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__' . $fkey);
-//   $pub_id = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__pub_id');
-//   $uname = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '--pub__uniquename');
-
-  // If the user provided a uniquename then we want to set the
-  // foreign key value to be the chado_record_idd
-  if ($uname) {
-
-    // Get the pub. If one with the same name and type is already present
-    // then use that. Otherwise, insert a new one.
-    if (!$pub_id) {
-      $pub = chado_generate_var('pub', array('uniquename' => $uname));
-      // Set the pub_id and FK value
-      tripal_chado_set_field_form_values($field_name, $form_state, $pub->pub_id, $delta, $table_name . '__pub_id');
-      $fkey_value = $element['#entity']->chado_record_id;
-      tripal_chado_set_field_form_values($field_name, $form_state, $fkey_value, $delta, $table_name . '__' . $fkey);
-    }
-
-  }
-  else {
-    // If the $syn_name is not set, then remove the linker FK value to the base table.
-    tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__' . $fkey);
-    tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__pub_id');
-  }
-
-}
 /**
  * An Ajax callback for the pub widget.
  */

+ 68 - 71
tripal_chado/includes/TripalFields/chado_linker__synonym.inc

@@ -155,6 +155,74 @@ class chado_linker__synonym extends TripalField {
       '#required' => $element['#required'],
     );
   }
+  
+  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
+
+    $field_name = $element['#field_name'];
+    $delta = $element['#delta'];
+    $table_name = $element['#table_name'];
+    $fkey = $element['#fkey_field'];
+    
+    // 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.
+    if ($form_state['build_info']['form_id'] =='field_ui_field_edit_form') {
+      return;
+    }
+    
+    // Get the field values.
+    //   $fkey_value = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__' . $fkey);
+    //   $synonym_id = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__synonym_id');
+    //   $pub_id = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__pub_id');
+    //   $is_current = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__is_current');
+    //   $is_internal = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__is_internal');
+    //   $syn_name = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '--synonym__name');
+    //   $syn_type = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '--synonym__type_id');
+    
+    // Make sure that if a synonym is provided that a type is also
+    // provided.
+    if ($syn_name and !$syn_type) {
+      form_set_error(implode('][', $element ['#parents']) . '][' . $table_name . '--synonym__type_id', t("Please set a synonym type."));
+    }
+    if (!$syn_name and $syn_type) {
+      form_set_error(implode('][', $element ['#parents']) . '][' . $table_name . '--synonym__name', t("Please set a synonym name."));
+    }
+    // If the user provided a cv_id and a name then we want to set the
+    // foreign key value to be the chado_record_idd
+    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
+        tripal_chado_set_field_form_values($field_name, $form_state, $synonym->synonym_id, $delta, $table_name . '__synonym_id');
+        $fkey_value = $element['#entity']->chado_record_id;
+        tripal_chado_set_field_form_values($field_name, $form_state, $fkey_value, $delta, $table_name . '__' . $fkey);
+      }
+    
+      if (!$pub_id) {
+        $pub = chado_generate_var('pub', array('uniquename' => 'null'));
+        tripal_chado_set_field_form_values($field_name, $form_state, $pub->pub_id, $delta, $table_name . '__pub_id');
+      }
+    }
+    else {
+      // If the $syn_name is not set, then remove the linker FK value to the base table.
+      tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__' . $fkey);
+      tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__synonym_id');
+      tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__is_internal');
+      tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__is_current');
+    }
+  }
 
   /**
    * @see TripalField::load()
@@ -252,77 +320,6 @@ function theme_chado_linker__synonym_widget($variables) {
 
   return $layout;
 }
-/**
- * Callback function for validating the chado_linker__synonym_widget.
- */
-function chado_linker__synonym_widget_validate($element, &$form_state) {
-
-  $field_name = $element['#field_name'];
-  $delta = $element['#delta'];
-  $table_name = $element['#table_name'];
-  $fkey = $element['#fkey_field'];
-
-  // 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.
-  if ($form_state['build_info']['form_id'] =='field_ui_field_edit_form') {
-    return;
-  }
-
-  // Get the field values.
-//   $fkey_value = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__' . $fkey);
-//   $synonym_id = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__synonym_id');
-//   $pub_id = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__pub_id');
-//   $is_current = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__is_current');
-//   $is_internal = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '__is_internal');
-//   $syn_name = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '--synonym__name');
-//   $syn_type = tripal_chado_get_field_form_values($table_name, $form_state, $delta, $table_name . '--synonym__type_id');
-
-  // Make sure that if a synonym is provided that a type is also
-  // provided.
-  if ($syn_name and !$syn_type) {
-    form_set_error(implode('][', $element ['#parents']) . '][' . $table_name . '--synonym__type_id', t("Please set a synonym type."));
-  }
-  if (!$syn_name and $syn_type) {
-    form_set_error(implode('][', $element ['#parents']) . '][' . $table_name . '--synonym__name', t("Please set a synonym name."));
-  }
-  // If the user provided a cv_id and a name then we want to set the
-  // foreign key value to be the chado_record_idd
-  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
-      tripal_chado_set_field_form_values($field_name, $form_state, $synonym->synonym_id, $delta, $table_name . '__synonym_id');
-      $fkey_value = $element['#entity']->chado_record_id;
-      tripal_chado_set_field_form_values($field_name, $form_state, $fkey_value, $delta, $table_name . '__' . $fkey);
-    }
-
-    if (!$pub_id) {
-      $pub = chado_generate_var('pub', array('uniquename' => 'null'));
-      tripal_chado_set_field_form_values($field_name, $form_state, $pub->pub_id, $delta, $table_name . '__pub_id');
-    }
-  }
-  else {
-    // If the $syn_name is not set, then remove the linker FK value to the base table.
-    tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__' . $fkey);
-    tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__synonym_id');
-    tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__is_internal');
-    tripal_chado_set_field_form_values($field_name, $form_state, '', $delta, $table_name . '__is_current');
-  }
-
-}
 
 /**
  * An Ajax callback for the synonym widget.