Prechádzať zdrojové kódy

Got field querying working. Web services working again. Added theme function to TripalFieldWidget class

Stephen Ficklin 8 rokov pred
rodič
commit
9b8ddcc83b
44 zmenil súbory, kde vykonal 693 pridanie a 922 odobranie
  1. 1 0
      tripal/includes/TripalFieldQuery.inc
  2. 39 7
      tripal/includes/TripalFields/TripalFieldWidget.inc
  3. 30 2
      tripal/includes/tripal.fields.inc
  4. 6 0
      tripal/tripal.module
  5. 0 8
      tripal_chado/includes/TripalFields/chado_linker__contact/chado_linker__contact.inc
  6. 0 15
      tripal_chado/includes/TripalFields/chado_linker__contact/chado_linker__contact_widget.inc
  7. 0 8
      tripal_chado/includes/TripalFields/chado_linker__cvterm/chado_linker__cvterm.inc
  8. 0 16
      tripal_chado/includes/TripalFields/chado_linker__cvterm/chado_linker__cvterm_widget.inc
  9. 0 15
      tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_widget.inc
  10. 40 45
      tripal_chado/includes/TripalFields/data__accession/data__accession_widget.inc
  11. 0 15
      tripal_chado/includes/TripalFields/data__protein_sequence/data__protein_sequence_widget.inc
  12. 0 14
      tripal_chado/includes/TripalFields/data__sequence/data__sequence_widget.inc
  13. 1 16
      tripal_chado/includes/TripalFields/data__sequence_checksum/data__sequence_checksum_widget.inc
  14. 0 9
      tripal_chado/includes/TripalFields/data__sequence_coordinates/data__sequence_coordinates.inc
  15. 0 14
      tripal_chado/includes/TripalFields/data__sequence_coordinates/data__sequence_coordinates_widget.inc
  16. 0 15
      tripal_chado/includes/TripalFields/data__sequence_length/data__sequence_length_widget.inc
  17. 0 9
      tripal_chado/includes/TripalFields/go__gene_expression/go__gene_expression.inc
  18. 1 16
      tripal_chado/includes/TripalFields/go__gene_expression/go__gene_expression_widget.inc
  19. 13 0
      tripal_chado/includes/TripalFields/obi__organism/obi__organism_widget.inc
  20. 0 9
      tripal_chado/includes/TripalFields/ogi__location_on_map/ogi__location_on_map.inc
  21. 0 15
      tripal_chado/includes/TripalFields/ogi__location_on_map/ogi__location_on_map_widget.inc
  22. 53 74
      tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference.inc
  23. 65 62
      tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_widget.inc
  24. 0 9
      tripal_chado/includes/TripalFields/sbo__phenotype/sbo__phenotype.inc
  25. 0 15
      tripal_chado/includes/TripalFields/sbo__phenotype/sbo__phenotype_widget.inc
  26. 157 10
      tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship.inc
  27. 23 194
      tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_widget.inc
  28. 0 9
      tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name.inc
  29. 16 35
      tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name_widget.inc
  30. 0 9
      tripal_chado/includes/TripalFields/schema__publication/schema__publication.inc
  31. 28 49
      tripal_chado/includes/TripalFields/schema__publication/schema__publication_widget.inc
  32. 0 14
      tripal_chado/includes/TripalFields/so__cds/so__cds_widget.inc
  33. 0 9
      tripal_chado/includes/TripalFields/so__genotype/so__genotype.inc
  34. 0 15
      tripal_chado/includes/TripalFields/so__genotype/so__genotype_widget.inc
  35. 0 9
      tripal_chado/includes/TripalFields/so__transcript/so__transcript.inc
  36. 0 15
      tripal_chado/includes/TripalFields/so__transcript/so__transcript_widget.inc
  37. 0 10
      tripal_chado/includes/TripalFields/taxrank__infraspecific_taxon/taxrank__infraspecific_taxon.inc
  38. 3 18
      tripal_chado/includes/TripalFields/taxrank__infraspecific_taxon/taxrank__infraspecific_taxon_widget.inc
  39. 108 81
      tripal_chado/includes/tripal_chado.field_storage.inc
  40. 91 23
      tripal_chado/includes/tripal_chado.publish.inc
  41. 8 8
      tripal_chado/tripal_chado.module
  42. 0 1
      tripal_chado/tripal_chado.views.inc
  43. 9 4
      tripal_ws/includes/tripal_ws.rest_v0.1.inc
  44. 1 1
      tripal_ws/tripal_ws.module

+ 1 - 0
tripal/includes/TripalFieldQuery.inc

@@ -9,6 +9,7 @@ class TripalFieldQuery extends EntityFieldQuery {
   protected $field_storage = array();
 
   public function execute() {
+
     // Give a chance to other modules to alter the query.
     drupal_alter('entity_query', $this);
     $this->altered = TRUE;

+ 39 - 7
tripal/includes/TripalFields/TripalFieldWidget.inc

@@ -109,19 +109,19 @@ class TripalFieldWidget {
     $widget['#field'] = $this->field;
     $widget['#instance'] = $this->instance;
     $widget['#element_validate'] = array('tripal_field_widget_form_validate');
+    $widget['#theme'] = 'tripal_field_default';
   }
 
   /**
    * Performs validation of the widgetForm.
    *
-   * 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
+   * Use this validate to ensure that form values are entered correctly.
+   * The 'value' key of this field must be set in the $form_state['values']
+   * array anytime data is entered by the user.  It may be the case that there
+   * are other fields for helping select a value. In the end those helper
+   * fields must be used to set the 'value' field.
    */
-  public function validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+  public function validate($element, $form, &$form_state, $langcode, $delta) {
 
   }
 
@@ -164,4 +164,36 @@ class TripalFieldWidget {
   public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
 
   }
+
+  /**
+   * The theme function for the widget.
+   *
+   * @param $element
+   * A form element array containing basic properties for the widget:
+   *  - #entity_type: The name of the entity the field is attached to.
+   *  - #bundle: The name of the field bundle the field is contained in.
+   *  - #field_name: The name of the field.
+   *  - #language: The language the field is being edited in.
+   *  - #field_parents: The 'parents' space for the field in the form. Most
+   *    widgets can simply overlook this property. This identifies the location
+   *    where the field values are placed within $form_state['values'], and is
+   *    used to access processing information for the field through the
+   *    field_form_get_state() and field_form_set_state() functions.
+   *  - #columns: A list of field storage columns of the field.
+   *  - #title: The sanitized element label for the field instance, ready for
+   *    output.
+   *  - #description: The sanitized element description for the field instance,
+   *    ready for output.
+   *  - #required: A Boolean indicating whether the element value is required;
+   *    for required multiple value fields, only the first widget's values are
+   *    required.
+   *  - #delta: The order of this item in the array of subelements; see
+   *    $delta above
+   *
+   * @return
+   *   A drupal renderable array or HTML or an empty string if no
+   *   theming is to be applied.
+   */
+  public function theme($element) {
+  }
 }

+ 30 - 2
tripal/includes/tripal.fields.inc

@@ -587,8 +587,17 @@ function tripal_field_instance_settings_form_submit($form, &$form_state) {
 /**
  *
  */
-function tripal_field_widget_form_validate($form, &$form_state) {
-
+function tripal_field_widget_form_validate($element, &$form_state, $form) {
+  $field = $element['#field'];
+  $instance = $element['#instance'];
+  $widget_class = $element['#field_name'] . '_widget';
+  $langcode = $element['#language'];
+  $delta = $element['#delta'];
+  tripal_load_include_field_class($widget_class);
+  if (class_exists($widget_class)) {
+    $widget = new $widget_class($field, $instance);
+    $widget->validate($element, $form, $form_state, $langcode, $delta);
+  }
 }
 
 
@@ -756,3 +765,22 @@ function tripal_field_is_empty($item, $field) {
   // Otherwise, the field is empty.
   return TRUE;
 }
+
+/**
+ * Theme function for all TripalFieldWidget objects.
+ *
+ * @param $variables
+ */
+function theme_tripal_field_default($variables) {
+  $element = $variables['element'];
+  $field = $element['#field'];
+  $instance = $element['#instance'];
+  $widget_class = $element['#field_name'] . '_widget';
+  $langcode = $element['#language'];
+  $delta = $element['#delta'];
+  tripal_load_include_field_class($widget_class);
+  if (class_exists($widget_class)) {
+    $widget = new $widget_class($field, $instance);
+    return $widget->theme($element);
+  }
+}

+ 6 - 0
tripal/tripal.module

@@ -346,7 +346,13 @@ function tripal_theme($existing, $type, $theme, $path) {
     'tripal_add_list' => array(
       'variables' => array('content' => NULL),
     ),
+    // Themeing for all fields.
+    'tripal_field_default' => array(
+      'render element' => 'element',
+      'file' => 'includes/tripal.fields.inc',
+    ),
   );
+
   return $themes;
 }
 

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

@@ -57,14 +57,6 @@ class chado_linker__contact extends ChadoField {
   protected $instance;
 
 
-  /**
-   *
-   * @see TripalField::validate()
-   */
-  public function validate($entity_type, $entity, $field, $items, &$errors) {
-
-  }
-
 
   /**
    *

+ 0 - 15
tripal_chado/includes/TripalFields/chado_linker__contact/chado_linker__contact_widget.inc

@@ -46,7 +46,6 @@ class chado_linker__contact_widget extends ChadoFieldWidget {
 
     $widget['#table_name'] = $table_name;
     $widget['#fkey_field'] = $fkey;
-    $widget['#theme'] = 'chado_linker__contact_widget';
     $widget['#prefix'] =  "<span id='$table_name-$delta'>";
     $widget['#suffix'] =  "</span>";
 
@@ -83,20 +82,6 @@ class chado_linker__contact_widget extends ChadoFieldWidget {
     );
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
 
   /**
    *

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

@@ -50,14 +50,6 @@ class chado_linker__cvterm extends ChadoField {
   // and field_create_instance().
   public static $no_ui = FALSE;
 
-  /**
-   *
-   * @see TripalField::validate()
-   */
-  public function validate($entity_type, $entity, $field, $items, &$errors) {
-
-  }
-
 
   /**
    *

+ 0 - 16
tripal_chado/includes/TripalFields/chado_linker__cvterm/chado_linker__cvterm_widget.inc

@@ -75,7 +75,6 @@ class chado_linker__cvterm_widget extends ChadoFieldWidget {
 
     $widget['#table_name'] = $chado_table;
     $widget['#fkey_field'] = $fkey;
-    $widget['#theme'] = 'chado_linker__cvterm_widget';
     $widget['#prefix'] =  "<span id='$table_name-$delta'>";
     $widget['#suffix'] =  "</span>";
 
@@ -143,21 +142,6 @@ class chado_linker__cvterm_widget extends ChadoFieldWidget {
     );
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
-
   /**
    *
    * @see TripalFieldWidget::submit()

+ 0 - 15
tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_widget.inc

@@ -84,21 +84,6 @@ class chado_linker__prop_widget extends ChadoFieldWidget {
     );
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
-
   /**
    *
    * @see TripalFieldWidget::submit()

+ 40 - 45
tripal_chado/includes/TripalFields/data__accession/data__accession_widget.inc

@@ -47,7 +47,6 @@ class data__accession_widget extends ChadoFieldWidget {
     $options = tripal_get_db_select_options();
 
     //$widget['#element_validate'] = array('chado_base__dbxref_id_widget_validate');
-    $widget['#theme'] = 'data__accession_widget';
     $widget['#prefix'] =  "<span id='$field_name-dbxref--db-id'>";
     $widget['#suffix'] =  "</span>";
 
@@ -56,7 +55,7 @@ class data__accession_widget extends ChadoFieldWidget {
       '#title' => $element['#title'],
       '#description' =>  $element['#description'],
       '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
-      '#theme' => 'data__accession_widget',
+//      '#theme' => 'data__accession_widget',
       //'#collapsible' => TRUE,
       //'#collapsed' => $collapsed,
     );
@@ -152,6 +151,45 @@ class data__accession_widget extends ChadoFieldWidget {
       }
     }
   }
+
+  /**
+   * @see TripalFieldWidget::theme()
+   */
+  public function theme($element) {
+    $layout = "
+      <div class=\"primary-dbxref-widget\">
+        <div class=\"primary-dbxref-widget-item\">" .
+          drupal_render($element['db_id']) . "
+        </div>
+        <div class=\"primary-dbxref-widget-item\">" .
+          drupal_render($element['accession']) . "
+        </div>
+        <div class=\"primary-dbxref-widget-item\">" .
+          drupal_render($element['version']) . "
+        </div>
+        <div class=\"primary-dbxref-widget-item\">" .
+          drupal_render($element['description']) . "
+        </div>
+        <div class=\"primary-dbxref-widget-links\">" . drupal_render($element['links']) . "</div>
+      </div>
+    ";
+
+    //   $classes = array();
+    //   $classes[] = 'collapsible';
+    //   $theme_settings = $element['#theme_settings'];
+    //   if ($theme_settings['#collapsed'] == FALSE) {
+    //     $classes[] = 'collapsed';
+    //   }
+    $fieldset = array(
+      '#title' => $element['#title'],
+      '#value' => '',
+      '#description' => $element['#description'],
+      '#children' => $layout,
+      //    '#attributes' => array('class' => $classes),
+    );
+
+    return theme('fieldset', array('element' => $fieldset));
+  }
 }
 
 /**
@@ -182,46 +220,3 @@ function data__accession_widget_form_ajax_callback($form, $form_state) {
   return $form[$field_name];
 }
 
-function theme_data__accession_widget($variables) {
-  $element = $variables['element'];
-  $field_name = $element['#field_name'];
-  $field = field_info_field($field_name);
-  $field_type = $field['type'];
-  $field_table = $this->instant['settings']['chado_table'];
-  $field_column = $this->instant['settings']['chado_column'];
-  $field_prefix = 'chado-' . $field_table . '__' . $field_column;
-
-  $layout = "
-      <div class=\"primary-dbxref-widget\">
-        <div class=\"primary-dbxref-widget-item\">" .
-        drupal_render($element['db_id']) . "
-        </div>
-        <div class=\"primary-dbxref-widget-item\">" .
-        drupal_render($element['accession']) . "
-        </div>
-        <div class=\"primary-dbxref-widget-item\">" .
-        drupal_render($element['version']) . "
-        </div>
-        <div class=\"primary-dbxref-widget-item\">" .
-        drupal_render($element['description']) . "
-        </div>
-        <div class=\"primary-dbxref-widget-links\">" . drupal_render($element['links']) . "</div>
-      </div>
-    ";
-
-  //   $classes = array();
-  //   $classes[] = 'collapsible';
-  //   $theme_settings = $element['#theme_settings'];
-  //   if ($theme_settings['#collapsed'] == FALSE) {
-  //     $classes[] = 'collapsed';
-  //   }
-  $fieldset = array(
-    '#title' => $element['#title'],
-    '#value' => '',
-    '#description' => $element['#description'],
-    '#children' => $layout,
-    //    '#attributes' => array('class' => $classes),
-  );
-
-  return theme('fieldset', array('element' => $fieldset));
-}

+ 0 - 15
tripal_chado/includes/TripalFields/data__protein_sequence/data__protein_sequence_widget.inc

@@ -17,21 +17,6 @@ class data__protein_sequence_widget extends ChadoFieldWidget {
     // TODO: add the form for setting a protein sequence.
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
-
   /**
    *
    * @see TripalFieldWidget::submit()

+ 0 - 14
tripal_chado/includes/TripalFields/data__sequence/data__sequence_widget.inc

@@ -44,20 +44,6 @@ class data__sequence_widget extends ChadoFieldWidget {
     );
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
 
   /**
    *

+ 1 - 16
tripal_chado/includes/TripalFields/data__sequence_checksum/data__sequence_checksum_widget.inc

@@ -36,21 +36,6 @@ class data__sequence_checksum_widget extends ChadoFieldWidget {
     );
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
-
   /**
    *
    * @see TripalFieldWidget::submit()
@@ -63,7 +48,7 @@ class data__sequence_checksum_widget extends ChadoFieldWidget {
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
 
-    // Get the residues so we can calculate teh length.
+    // Get the residues so we can calculate the length.
     $residues = isset($form_state['values']['feature__residues'][$langcode][0]['chado-feature__residues']) ? $form_state['values']['feature__residues'][$langcode][0]['chado-feature__residues'] : '';
 
     if ($residues) {

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

@@ -55,15 +55,6 @@ class data__sequence_coordinates extends ChadoField {
   protected $instance;
 
 
-  /**
-   *
-   * @see TripalField::validate()
-   */
-  public function validate($entity_type, $entity, $field, $items, &$errors) {
-
-  }
-
-
   /**
    *
    * @see TripalField::load()

+ 0 - 14
tripal_chado/includes/TripalFields/data__sequence_coordinates/data__sequence_coordinates_widget.inc

@@ -15,20 +15,6 @@ class data__sequence_coordinates_widget extends ChadoFieldWidget {
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
 
   /**
    *

+ 0 - 15
tripal_chado/includes/TripalFields/data__sequence_length/data__sequence_length_widget.inc

@@ -33,21 +33,6 @@ class data__sequence_length_widget extends ChadoFieldWidget {
     );
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
-
   /**
    *
    * @see TripalFieldWidget::submit()

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

@@ -60,15 +60,6 @@ class go__gene_expression extends ChadoField {
   protected $instance;
 
 
-  /**
-   *
-   * @see TripalField::validate()
-   */
-  public function validate($entity_type, $entity, $field, $items, &$errors) {
-
-  }
-
-
   /**
    *
    * @see TripalField::load()

+ 1 - 16
tripal_chado/includes/TripalFields/go__gene_expression/go__gene_expression_widget.inc

@@ -15,21 +15,6 @@ class go__gene_expression_widget extends ChadoFieldWidget {
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
-
   /**
    *
    * @see TripalFieldWidget::submit()
@@ -37,5 +22,5 @@ class go__gene_expression_widget extends ChadoFieldWidget {
   public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
 
   }
-  
+
 }

+ 13 - 0
tripal_chado/includes/TripalFields/obi__organism/obi__organism_widget.inc

@@ -43,4 +43,17 @@ class obi__organism_widget extends ChadoFieldWidget {
       '#delta' => $delta,
     );
   }
+
+  /**
+   * @see TripalFieldWidget::validate()
+   */
+  public function validate($element, $form, &$form_state, $langcode, $delta) {
+
+    $field_name = $this->field['field_name'];
+    $field_table = $this->instance['settings']['chado_table'];
+
+    // Make sure the value is set to the organism_id
+    $organism_id = $form_state['values'][$field_name][$langcode][0]['chado-' . $field_table . '__organism_id'];
+    $form_state['values'][$field_name][$langcode][0]['value'] = $organism_id;
+  }
 }

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

@@ -55,15 +55,6 @@ class ogi__location_on_map extends ChadoField {
   protected $instance;
 
 
-  /**
-   *
-   * @see TripalField::validate()
-   */
-  public function validate($entity_type, $entity, $field, $items, &$errors) {
-
-  }
-
-
   /**
    *
    * @see TripalField::load()

+ 0 - 15
tripal_chado/includes/TripalFields/ogi__location_on_map/ogi__location_on_map_widget.inc

@@ -15,21 +15,6 @@ class ogi__location_on_map_widget extends ChadoFieldWidget {
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
-
   /**
    *
    * @see TripalFieldWidget::submit()

+ 53 - 74
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference.inc

@@ -57,15 +57,6 @@ class sbo__database_cross_reference extends ChadoField {
   protected $instance;
 
 
-  /**
-   *
-   * @see TripalField::validate()
-   */
-  public function validate($entity_type, $entity, $field, $items, &$errors) {
-
-  }
-
-
   /**
    *
    * @see TripalField::load()
@@ -124,70 +115,58 @@ class sbo__database_cross_reference extends ChadoField {
       }
     }
   }
-}
-
-/**
- * Theme function for the dbxref_id_widget.
- *
- * @param $variables
- */
-function theme_sbo__database_cross_reference_widget($variables) {
-  $element = $variables['element'];
-
-  // These two fields were added to the widget to help identify the fields
-  // for layout.
-  $table_name = $element['#table_name'];
-  $fkey = $element['#fkey_field'];
-
-  $layout = "
-      <div class=\"secondary-dbxref-widget\">
-        <div class=\"secondary-dbxref-widget-item\">" .
-        drupal_render($element['db_id']) . "
-        </div>
-        <div class=\"secondary-dbxref-widget-item\">" .
-        drupal_render($element['accession']) . "
-        </div>
-        <div class=\"secondary-dbxref-widget-item\">" .
-        drupal_render($element['version']) . "
-        </div>
-        <div class=\"secondary-dbxref-widget-item\">" .
-        drupal_render($element['description']) . "
-        </div>
-        <div class=\"secondary-dbxref-widget-links\">" . drupal_render($element['links']) . "</div>
-      </div>
-    ";
-
-        return $layout;
-}
-
-/**
- * An Ajax callback for the dbxref widget.
- */
-function sbo__database_cross_reference_widget_form_ajax_callback($form, $form_state) {
-
-  $field_name = $form_state['triggering_element']['#parents'][0];
-  $delta = $form_state['triggering_element']['#parents'][2];
-  $field = field_info_field($field_name);
-  $field_type = $field['type'];
-  $field_table = $this->instance['settings']['chado_table'];
-  $field_column = $this->instance['settings']['chado_column'];
-  $field_prefix = 'chado-' . $field_table . '__dbxref_id';
-
-  // Check to see if this dbxref already exists. If not then
-  // give a notice to the user that the dbxref will be added.
-  $db_id = $form_state['values'][$field_name]['und'][$delta]['db_id'];
-  $db_id = $form_state['values'][$field_name]['und'][$delta]['accession'];
-  if ($db_id and $accession) {
-    $values = array(
-      'db_id' => $db_id,
-      'accession' => $accession,
-    );
-    $options = array('is_duplicate' => TRUE);
-    $has_duplicate = chado_select_record('dbxref', array('*'), $values, $options);
-    if (!$has_duplicate) {
-      drupal_set_message('The selected cross reference is new and will be added for future auto completions.');
-    }
-  }
+  /**
+   * @see TripalField::validate()
+   */
+  public function validate($entity_type, $entity, $field, $items, &$errors) {
 
-  return $form[$field_name]['und'][$delta];
+    $field_name = $this->field['field_name'];
+    $field_type = $this->field['type'];
+    $table_name = $this->instance['settings']['chado_table'];
+    $field_table = $this->instance['settings']['chado_table'];
+    $field_column = $this->instance['settings']['chado_column'];
+    $base_table = $this->instance['settings']['base_table'];
+    $schema = chado_get_schema($table_name);
+    $pkey = $schema['primary key'][0];
+    $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
+    $fkey = $fkeys[0];
+
+
+    // Get the field values.
+    foreach ($form_state[$field_name] 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'];
+
+      // 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) {
+      $errors[$field_name][$delta]['und'][] = array(
+      'message' => t("A database and the accession must both be provided."),
+          'error' => 'sbo__database_cross_reference',
+        );
+      }
+          if ($db_id and !$accession) {
+          $errors[$field_name][$delta]['und'][] = array(
+            'message' => t("A database and the accession must both be provided."),
+          'error' => 'sbo__database_cross_reference',
+        );
+      }
+                if (!$db_id and !$accession and ($version or $description)) {
+                $errors[$field_name][$delta]['und'][] = array(
+                  'message' => t("A database and the accession must both be provided."),
+          'error' => 'sbo__database_cross_reference',
+        );
+                }
+                }
+    }
 }

+ 65 - 62
tripal_chado/includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_widget.inc

@@ -64,7 +64,6 @@ class sbo__database_cross_reference_widget extends ChadoFieldWidget {
     $widget['#table_name'] = $chado_table;
     $widget['#fkey_field'] = $fkey;
     //$widget['#element_validate'] = array('sbo__database_cross_reference_widget_validate');
-    $widget['#theme'] = 'sbo__database_cross_reference_widget';
     $widget['#prefix'] =  "<span id='$field_name-dbxref--db-id-$delta'>";
     $widget['#suffix'] =  "</span>";
 
@@ -142,67 +141,6 @@ class sbo__database_cross_reference_widget extends ChadoFieldWidget {
     }
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-    $field_name = $this->field['field_name'];
-    $field_type = $this->field['type'];
-    $table_name = $this->instance['settings']['chado_table'];
-    $field_table = $this->instance['settings']['chado_table'];
-    $field_column = $this->instance['settings']['chado_column'];
-    $base_table = $this->instance['settings']['base_table'];
-    $schema = chado_get_schema($table_name);
-    $pkey = $schema['primary key'][0];
-    $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
-    $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'];
-
-      // 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) {
-        $errors[$field_name][$delta]['und'][] = array(
-          'message' => t("A database and the accession must both be provided."),
-          'error' => 'sbo__database_cross_reference',
-        );
-      }
-      if ($db_id and !$accession) {
-        $errors[$field_name][$delta]['und'][] = array(
-          'message' => t("A database and the accession must both be provided."),
-          'error' => 'sbo__database_cross_reference',
-        );
-      }
-      if (!$db_id and !$accession and ($version or $description)) {
-        $errors[$field_name][$delta]['und'][] = array(
-          'message' => t("A database and the accession must both be provided."),
-          'error' => 'sbo__database_cross_reference',
-        );
-      }
-    }
-  }
-
 
   /**
    *
@@ -245,4 +183,69 @@ class sbo__database_cross_reference_widget extends ChadoFieldWidget {
       $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__dbxref_id'] = '';
     }
   }
+
+  /**
+   * @see TripalFieldWidget::theme()
+   */
+  public function theme($element) {
+    $element = $variables['element'];
+
+    // These two fields were added to the widget to help identify the fields
+    // for layout.
+    $table_name = $element['#table_name'];
+    $fkey = $element['#fkey_field'];
+
+    $layout = "
+      <div class=\"secondary-dbxref-widget\">
+        <div class=\"secondary-dbxref-widget-item\">" .
+          drupal_render($element['db_id']) . "
+        </div>
+        <div class=\"secondary-dbxref-widget-item\">" .
+          drupal_render($element['accession']) . "
+        </div>
+        <div class=\"secondary-dbxref-widget-item\">" .
+          drupal_render($element['version']) . "
+        </div>
+        <div class=\"secondary-dbxref-widget-item\">" .
+          drupal_render($element['description']) . "
+        </div>
+        <div class=\"secondary-dbxref-widget-links\">" . drupal_render($element['links']) . "</div>
+      </div>
+    ";
+
+    return $layout;
+  }
 }
+
+
+/**
+ * An Ajax callback for the dbxref widget.
+ */
+function sbo__database_cross_reference_widget_form_ajax_callback($form, $form_state) {
+
+  $field_name = $form_state['triggering_element']['#parents'][0];
+  $delta = $form_state['triggering_element']['#parents'][2];
+  $field = field_info_field($field_name);
+  $field_type = $field['type'];
+  $field_table = $this->instance['settings']['chado_table'];
+  $field_column = $this->instance['settings']['chado_column'];
+  $field_prefix = 'chado-' . $field_table . '__dbxref_id';
+
+  // Check to see if this dbxref already exists. If not then
+  // give a notice to the user that the dbxref will be added.
+  $db_id = $form_state['values'][$field_name]['und'][$delta]['db_id'];
+  $db_id = $form_state['values'][$field_name]['und'][$delta]['accession'];
+  if ($db_id and $accession) {
+    $values = array(
+      'db_id' => $db_id,
+      'accession' => $accession,
+    );
+    $options = array('is_duplicate' => TRUE);
+    $has_duplicate = chado_select_record('dbxref', array('*'), $values, $options);
+    if (!$has_duplicate) {
+      drupal_set_message('The selected cross reference is new and will be added for future auto completions.');
+    }
+  }
+
+  return $form[$field_name]['und'][$delta];
+}

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

@@ -57,15 +57,6 @@ class sbo__phenotype extends ChadoField {
   protected $instance;
 
 
-  /**
-   *
-   * @see TripalField::validate()
-   */
-  public function validate($entity_type, $entity, $field, $items, &$errors) {
-
-  }
-
-
   /**
    *
    * @see TripalField::load()

+ 0 - 15
tripal_chado/includes/TripalFields/sbo__phenotype/sbo__phenotype_widget.inc

@@ -15,21 +15,6 @@ class sbo__phenotype_widget extends ChadoFieldWidget {
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
-
   /**
    *
    * @see TripalFieldWidget::submit()

+ 157 - 10
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship.inc

@@ -55,15 +55,6 @@ class sbo__relationship extends ChadoField {
   protected $instance;
 
 
-  /**
-   *
-   * @see TripalField::validate()
-   */
-  public function validate($entity_type, $entity, $field, $items, &$errors) {
-
-  }
-
-
   /**
    *
    * @see TripalField::load()
@@ -367,7 +358,6 @@ class sbo__relationship extends ChadoField {
           term for the relationship type.'),
       '#collapsed' => TRUE,
       '#collapsible' => TRUE,
-      '#theme' => 'sbo__relationship_instance_settings'
     );
     //     $element['instructions'] = array(
     //       '#type' => 'item',
@@ -568,4 +558,161 @@ class sbo__relationship extends ChadoField {
         }
   }
 
+  /**
+   * @see TripalField::validate()
+   */
+  public function validate($entity_type, $entity, $field, $items, &$errors) {
+    $field_name = $this->field['field_name'];
+    $field_type = $this->field['type'];
+    $field_table = $this->instance['settings']['chado_table'];
+    $field_column = $this->instance['settings']['chado_column'];
+    $base_table = $this->instance['settings']['base_table'];
+
+    $schema = chado_get_schema($field_table);
+    $fkeys = $schema['foreign keys'];
+
+    // Handle special cases
+    $subject_id_key = 'subject_id';
+    $object_id_key = 'object_id';
+    if ($field_table == 'nd_reagent_relationship') {
+      $subject_id_key = 'subject_reagent_id';
+      $object_id_key = 'object_reagent_id';
+    }
+    else if ($field_table == 'project_relationship') {
+      $subject_id_key = 'subject_project_id';
+      $object_id_key = 'object_project_id';
+    }
+
+    foreach ($items as $delta => $item) {
+      $subject_id = $item['chado' . $field_table . '__' . $subject_id_key];
+      $object_id = $item['chado' . $field_table . '__' . $object_id_key];
+      $type_id = $item['chado' . $field_table . '__type_id'];
+      $type_id = isset($item['type_id']) ? $item['chado' . $field_table . '__type_id'] : $type_id;
+      $type_name = isset($item['type_name']) ? $item['type_name'] : '';
+      $subject_name = $item['subject_name'];
+      $object_name = $item['object_name'];
+
+
+      // If the row is empty then just continue, there's nothing to validate.
+      if (!$type_id and !$type_name and !$subject_name and !$object_name) {
+        continue;
+      }
+
+      // Make sure we have values for all of the fields.
+      $form_error = FALSE;
+      if (!$type_name && !$type_id) {
+        $errors[$this->field['field_name']][$langcode][$delta][] = array(
+          'error' => 'sbo__relationship',
+          'message' => t("Please provide the type of relationship."),
+        );
+      }
+      if ($entity and !$subject_name) {
+        $errors[$this->field['field_name']][$langcode][$delta][] = array(
+          'error' => 'sbo__relationship',
+          'message' => t("Please provide the subject of the relationship."),
+        );
+      }
+      if ($entity and !$object_name) {
+        $errors[$this->field['field_name']][$langcode][$delta][] = array(
+          'error' => 'sbo__relationship',
+          'message' => t("Please provide the object of the relationship."),
+        );
+      }
+      if ($form_error) {
+        continue;
+      }
+
+      // Before submitting this form we need to make sure that our subject_id and
+      // object_ids are real records.  There are two ways to get the record, either
+      // just with the text value or with an [id: \d+] string embedded.  If the
+      // later we will pull it out.
+      $subject_id = '';
+      $fkey_rcolumn = $fkeys[$base_table]['columns'][$subject_id_key];
+      $matches = array();
+      if ($entity) {
+        if(preg_match('/\[id: (\d+)\]/', $subject_name, $matches)) {
+          $subject_id =  $matches[1];
+          $values = array($fkey_rcolumn => $subject_id);
+          $subject = chado_select_record($base_table, array($fkey_rcolumn), $values);
+          if (count($subject) == 0) {
+            $errors[$this->field['field_name']][$langcode][$delta][] = array(
+              'error' => 'sbo__relationship',
+              'message' => t("The subject record cannot be found using the specified id (e.g. [id: xx])."),
+            );
+          }
+        }
+        else {
+          $values = array('uniquename' => $subject_name);
+          $subject = chado_select_record($base_table, array($fkey_rcolumn), $values);
+          if (count($subject) == 0) {
+            $errors[$this->field['field_name']][$langcode][$delta][] = array(
+              'error' => 'sbo__relationship',
+              'message' => t("The subject record cannot be found. Please check spelling."),
+            );
+          }
+          elseif (count($subject) > 1) {
+            $errors[$this->field['field_name']][$langcode][$delta][] = array(
+              'error' => 'sbo__relationship',
+              'message' => t("The subject is not unique and therefore the relationship cannot be made."),
+            );
+          }
+        }
+      }
+
+      // Now check for a matching object.
+      $object_id = '';
+      $fkey_rcolumn = $fkeys[$base_table]['columns'][$object_id_key];
+      $matches = array();
+      if ($entity) {
+        if (preg_match('/\[id: (\d+)\]/', $object_name, $matches)) {
+          $object_id = $matches[1];
+          $values = array($fkey_rcolumn => $object_id);
+          $object = chado_select_record($base_table, array($fkey_rcolumn), $values);
+          if (count($subject) == 0) {
+            $errors[$this->field['field_name']][$langcode][$delta][] = array(
+              'error' => 'sbo__relationship',
+              'message' => t("The object record cannot be found using the specified id (e.g. [id: xx])."),
+            );
+          }
+        }
+        else {
+          $values = array('uniquename' => $object_name);
+          $object = chado_select_record($base_table, array($fkey_rcolumn), $values);
+          if (count($object) == 0) {
+            $errors[$this->field['field_name']][$langcode][$delta][] = array(
+              'error' => 'sbo__relationship',
+              'message' => t("The object record cannot be found. Please check spelling."),
+            );;
+          }
+          elseif (count($object) > 1) {
+            $errors[$this->field['field_name']][$langcode][$delta][] = array(
+              'error' => 'sbo__relationship',
+              'message' =>  t("The object is not unique and therefore the relationship cannot be made."),
+            );
+          }
+        }
+      }
+
+      // Make sure that either our object or our subject refers to the base record.
+      if ($entity) {
+        $chado_record_id = $entity->chado_record_id;
+        if ($object_id != $chado_record_id  and $subject_id != $chado_record_id) {
+          $errors[$this->field['field_name']][$langcode][$delta][] = array(
+            'error' => 'sbo__relationship',
+            'message' =>  t("Either the subject or the object in the relationship must refer to this record."),
+          );
+        }
+
+        // Make sure that the object and subject are not both the same thing.
+        if ($object_id == $subject_id) {
+          $errors[$this->field['field_name']][$langcode][$delta][] = array(
+            'error' => 'sbo__relationship',
+            'message' =>  t("The subject and the object in the relationship cannot both refer to the same record."),
+          );
+        }
+      }
+    }
+  }
+
+
 }

+ 23 - 194
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_widget.inc

@@ -120,7 +120,6 @@ class sbo__relationship_widget extends ChadoFieldWidget {
     $widget['#base_table'] = $base_table;
     $widget['#chado_record_id'] = isset($form['#entity']) ? $form['#entity']->chado_record_id : '';
     //$widget['#element_validate'] = array('sbo__relationship_validate');
-    $widget['#theme'] = 'sbo__relationship_widget';
     $widget['#prefix'] =  "<span id='$field_table-$delta'>";
     $widget['#suffix'] =  "</span>";
 
@@ -328,170 +327,6 @@ class sbo__relationship_widget extends ChadoFieldWidget {
     );
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-    $field_name = $this->field['field_name'];
-    $field_type = $this->field['type'];
-    $field_table = $this->instance['settings']['chado_table'];
-    $field_column = $this->instance['settings']['chado_column'];
-    $base_table = $this->instance['settings']['base_table'];
-
-    $schema = chado_get_schema($field_table);
-    $fkeys = $schema['foreign keys'];
-
-    // Handle special cases
-    $subject_id_key = 'subject_id';
-    $object_id_key = 'object_id';
-    if ($field_table == 'nd_reagent_relationship') {
-      $subject_id_key = 'subject_reagent_id';
-      $object_id_key = 'object_reagent_id';
-    }
-    else if ($field_table == 'project_relationship') {
-      $subject_id_key = 'subject_project_id';
-      $object_id_key = 'object_project_id';
-    }
-
-    foreach ($items as $delta => $item) {
-      $subject_id = $item['chado' . $field_table . '__' . $subject_id_key];
-      $object_id = $item['chado' . $field_table . '__' . $object_id_key];
-      $type_id = $item['chado' . $field_table . '__type_id'];
-      $type_id = isset($item['type_id']) ? $item['chado' . $field_table . '__type_id'] : $type_id;
-      $type_name = isset($item['type_name']) ? $item['type_name'] : '';
-      $subject_name = $item['subject_name'];
-      $object_name = $item['object_name'];
-
-
-      // If the row is empty then just continue, there's nothing to validate.
-      if (!$type_id and !$type_name and !$subject_name and !$object_name) {
-        continue;
-      }
-
-      // Make sure we have values for all of the fields.
-      $form_error = FALSE;
-      if (!$type_name && !$type_id) {
-        $errors[$this->field['field_name']][$langcode][$delta][] = array(
-          'error' => 'sbo__relationship',
-          'message' => t("Please provide the type of relationship."),
-        );
-      }
-      if ($entity and !$subject_name) {
-        $errors[$this->field['field_name']][$langcode][$delta][] = array(
-          'error' => 'sbo__relationship',
-          'message' => t("Please provide the subject of the relationship."),
-        );
-      }
-      if ($entity and !$object_name) {
-        $errors[$this->field['field_name']][$langcode][$delta][] = array(
-          'error' => 'sbo__relationship',
-          'message' => t("Please provide the object of the relationship."),
-        );
-      }
-      if ($form_error) {
-        continue;
-      }
-
-      // Before submitting this form we need to make sure that our subject_id and
-      // object_ids are real records.  There are two ways to get the record, either
-      // just with the text value or with an [id: \d+] string embedded.  If the
-      // later we will pull it out.
-      $subject_id = '';
-      $fkey_rcolumn = $fkeys[$base_table]['columns'][$subject_id_key];
-      $matches = array();
-      if ($entity) {
-        if(preg_match('/\[id: (\d+)\]/', $subject_name, $matches)) {
-          $subject_id =  $matches[1];
-          $values = array($fkey_rcolumn => $subject_id);
-          $subject = chado_select_record($base_table, array($fkey_rcolumn), $values);
-          if (count($subject) == 0) {
-            $errors[$this->field['field_name']][$langcode][$delta][] = array(
-              'error' => 'sbo__relationship',
-              'message' => t("The subject record cannot be found using the specified id (e.g. [id: xx])."),
-            );
-          }
-        }
-        else {
-          $values = array('uniquename' => $subject_name);
-          $subject = chado_select_record($base_table, array($fkey_rcolumn), $values);
-          if (count($subject) == 0) {
-            $errors[$this->field['field_name']][$langcode][$delta][] = array(
-              'error' => 'sbo__relationship',
-              'message' => t("The subject record cannot be found. Please check spelling."),
-            );
-          }
-          elseif (count($subject) > 1) {
-            $errors[$this->field['field_name']][$langcode][$delta][] = array(
-              'error' => 'sbo__relationship',
-              'message' => t("The subject is not unique and therefore the relationship cannot be made."),
-            );
-          }
-        }
-      }
-
-      // Now check for a matching object.
-      $object_id = '';
-      $fkey_rcolumn = $fkeys[$base_table]['columns'][$object_id_key];
-      $matches = array();
-      if ($entity) {
-        if (preg_match('/\[id: (\d+)\]/', $object_name, $matches)) {
-          $object_id = $matches[1];
-          $values = array($fkey_rcolumn => $object_id);
-          $object = chado_select_record($base_table, array($fkey_rcolumn), $values);
-          if (count($subject) == 0) {
-            $errors[$this->field['field_name']][$langcode][$delta][] = array(
-              'error' => 'sbo__relationship',
-              'message' => t("The object record cannot be found using the specified id (e.g. [id: xx])."),
-            );
-          }
-        }
-        else {
-          $values = array('uniquename' => $object_name);
-          $object = chado_select_record($base_table, array($fkey_rcolumn), $values);
-          if (count($object) == 0) {
-            $errors[$this->field['field_name']][$langcode][$delta][] = array(
-              'error' => 'sbo__relationship',
-              'message' => t("The object record cannot be found. Please check spelling."),
-            );;
-          }
-          elseif (count($object) > 1) {
-            $errors[$this->field['field_name']][$langcode][$delta][] = array(
-              'error' => 'sbo__relationship',
-              'message' =>  t("The object is not unique and therefore the relationship cannot be made."),
-            );
-          }
-        }
-      }
-
-      // Make sure that either our object or our subject refers to the base record.
-      if ($entity) {
-        $chado_record_id = $entity->chado_record_id;
-        if ($object_id != $chado_record_id  and $subject_id != $chado_record_id) {
-          $errors[$this->field['field_name']][$langcode][$delta][] = array(
-            'error' => 'sbo__relationship',
-            'message' =>  t("Either the subject or the object in the relationship must refer to this record."),
-          );
-        }
-
-        // Make sure that the object and subject are not both the same thing.
-        if ($object_id == $subject_id) {
-          $errors[$this->field['field_name']][$langcode][$delta][] = array(
-            'error' => 'sbo__relationship',
-            'message' =>  t("The subject and the object in the relationship cannot both refer to the same record."),
-          );
-        }
-      }
-    }
-  }
-
-
   /**
    *
    * @see TripalFieldWidget::submit()
@@ -564,39 +399,33 @@ class sbo__relationship_widget extends ChadoFieldWidget {
     $form_state['values'][$field_name][$langcode][$delta]['chado' . $field_table . '__type_id'] = $type_name;
     $form_state['values'][$field_name][$langcode][$delta]['chado' . $field_table . '__rank'] = $item['_weight'];
   }
-}
 
-
-/**
- * Theme function for the sbo__relationship_widget.
- */
-function theme_sbo__relationship_widget($variables) {
-  $element = $variables['element'];
-  $field_name = $element['#field_name'];
-  $field = field_info_field($field_name);
-  $field_type = $field['type'];
-  $field_table = $this->instance['settings']['chado_table'];
-  $field_column = $this->instance['settings']['chado_column'];
-  $layout = "
+  /**
+   * Theme function for the sbo__relationship_widget.
+   */
+  public function theme($element) {
+    $layout = "
       <div class=\"chado-linker--relationship-widget\">
         <div class=\"chado-linker--relationship-widget-item\">" .
-        drupal_render($element['subject_name']) . "
+          drupal_render($element['subject_name']) . "
         </div>
         <div class=\"chado-linker--relationship-widget-item\">" .
-        drupal_render($element['vocabulary']) . "
+          drupal_render($element['vocabulary']) . "
         </div>
         <div class=\"chado-linker--relationship-widget-item\">" .
-        drupal_render($element['type_name']) . "
+          drupal_render($element['type_name']) . "
         </div>
         <div class=\"chado-linker--relationship-widget-item\">" .
-        drupal_render($element['type_id']) . "
+          drupal_render($element['type_id']) . "
         </div>
-        <div class=\"chado-linker--relationship-widget-item\">" .
-        drupal_render($element['object_name']) . "
+        <div>" .
+          drupal_render($element['object_name']) . "
         </div>
       </div>
     ";
-        return $layout;
+    return $layout;
+  }
+
 }
 
 function theme_sbo__relationship_instance_settings ($variables) {
@@ -611,15 +440,15 @@ function theme_sbo__relationship_instance_settings ($variables) {
   $layout = drupal_render($option1);
   $layout .= drupal_render($option1_vocabs);
   $layout .=
-  drupal_render($option2) .
-  "<div class=\"chado-linker--relationship-instance-settings-option2\">" .
-  "<div class=\"chado-linker--relationship-instance-settings-option2-item\">" .
-  drupal_render($option2_vocab) .
-  "</div>" .
-  "<div class=\"chado-linker--relationship-instance-settings-option2-item\">" .
-  drupal_render($option2_parent) .
-  "</div>" .
-  "</div>";
+    drupal_render($option2) .
+    "<div class=\"chado-linker--relationship-instance-settings-option2\">" .
+    "<div class=\"chado-linker--relationship-instance-settings-option2-item\">" .
+    drupal_render($option2_vocab) .
+    "</div>" .
+    "<div class=\"chado-linker--relationship-instance-settings-option2-item\">" .
+    drupal_render($option2_parent) .
+    "</div>" .
+    "</div>";
   $layout .= drupal_render($option3);
   $layout .= drupal_render($rtype);
   return $layout;

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

@@ -55,15 +55,6 @@ class schema__alternate_name extends ChadoField {
   protected $instance;
 
 
-  /**
-   *
-   * @see TripalField::validate()
-   */
-  public function validate($entity_type, $entity, $field, $items, &$errors) {
-
-  }
-
-
   /**
    *
    * @see TripalField::load()

+ 16 - 35
tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name_widget.inc

@@ -73,7 +73,6 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
 
     $widget['#table_name'] = $table_name;
     $widget['#fkey_field'] = $fkey;
-    $widget['#theme'] = 'schema__alternate_name_widget';
     $widget['#prefix'] =  "<span id='$table_name-$delta'>";
     $widget['#suffix'] =  "</span>";
 
@@ -127,21 +126,6 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
     );
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
-
   /**
    *
    * @see TripalFieldWidget::submit()
@@ -201,40 +185,37 @@ class schema__alternate_name_widget extends ChadoFieldWidget {
       $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__is_current'] = '';
     }
   }
-}
-
 
-/**
- * Theme function for the synonym widget.
- *
- * @param $variables
- */
-function theme_schema__alternate_name_widget($variables) {
-  $element = $variables['element'];
+  /**
+   * @see TripalFieldWidget::theme()
+   */
+  public function theme($element) {
 
-  // These two fields were added to the widget to help identify the fields
-  // for layout.
-  $table_name = $element['#table_name'];
-  $fkey = $element['#fkey_field'];
+    // These two fields were added to the widget to help identify the fields
+    // for layout.
+    $table_name = $element['#table_name'];
+    $fkey = $element['#fkey_field'];
 
-  $layout = "
+    $layout = "
       <div class=\"synonym-widget\">
         <div class=\"synonym-widget-item\">" .
-        drupal_render($element['name']) . "
+          drupal_render($element['name']) . "
         </div>
         <div>" .
-        drupal_render($element['type_id']) . "
+          drupal_render($element['type_id']) . "
         </div>
         <div class=\"synonym-widget-item\">" .
-        drupal_render($element['chado-' . $table_name . '__is_internal']) . "
+          drupal_render($element['chado-' . $table_name . '__is_internal']) . "
         </div>
         <div>" .
-        drupal_render($element['chado-' . $table_name . '__is_current']) . "
+          drupal_render($element['chado-' . $table_name . '__is_current']) . "
         </div>
       </div>
     ";
 
-        return $layout;
+    return $layout;
+  }
+
 }
 
 /**

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

@@ -57,15 +57,6 @@ class schema__publication extends ChadoField {
   protected $instance;
 
 
-  /**
-   *
-   * @see TripalField::validate()
-   */
-  public function validate($entity_type, $entity, $field, $items, &$errors) {
-
-  }
-
-
   /**
    *
    * @see TripalField::load()

+ 28 - 49
tripal_chado/includes/TripalFields/schema__publication/schema__publication_widget.inc

@@ -15,7 +15,7 @@ class schema__publication_widget extends ChadoFieldWidget {
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
     $entity = $form['#entity'];
     $field_name = $this->field['field_name'];
-    
+
     // Get the FK column that links to the base table.
     $table_name = $this->instance['settings']['chado_table'];
     $base_table = $this->instance['settings']['base_table'];
@@ -23,13 +23,13 @@ class schema__publication_widget extends ChadoFieldWidget {
     $pkey = $schema['primary key'][0];
     $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
     $fkey = $fkeys[0];
-    
+
     // Get the field defaults.
     $record_id = '';
     $fkey_value = $element['#entity']->chado_record_id;
     $pub_id = '';
     $uname = '';
-    
+
     // If the field already has a value then it will come through the $items
     // array.  This happens when editing an existing record.
     if (count($items) > 0 and array_key_exists($delta, $items)) {
@@ -37,20 +37,19 @@ class schema__publication_widget extends ChadoFieldWidget {
       $pub_id = tripal_get_field_item_keyval($items, $delta, 'chado-' . $table_name . '__pub_id', $pub_id);
       $uname = tripal_get_field_item_keyval($items, $delta, 'uniquename', $uname);
     }
-    
+
     $schema = chado_get_schema('pub');
-    
+
     $widget['#table_name'] = $table_name;
     $widget['#fkey_field'] = $fkey;
-    $widget['#theme'] = 'schema__publication_widget';
     $widget['#prefix'] =  "<span id='$table_name-$delta'>";
     $widget['#suffix'] =  "</span>";
-    
+
     $widget['value'] = array(
       '#type' => 'value',
       '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
     );
-    
+
     $widget['chado-' . $table_name . '__' . $pkey] = array(
       '#type' => 'value',
       '#default_value' => $record_id,
@@ -63,7 +62,7 @@ class schema__publication_widget extends ChadoFieldWidget {
       '#type' => 'value',
       '#default_value' => $pub_id,
     );
-    
+
     $widget['uniquename'] = array(
       '#type' => 'textfield',
       '#title' => t('Publication'),
@@ -79,20 +78,6 @@ class schema__publication_widget extends ChadoFieldWidget {
     );
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
 
   /**
    *
@@ -107,19 +92,19 @@ class schema__publication_widget extends ChadoFieldWidget {
     $fkeys = array_values($schema['foreign keys'][$base_table]['columns']);
     $fkey = $fkeys[0];
     $field_name = $this->field['field_name'];
-    
+
     // Get the field values.
     $fkey_value = isset($form_state['values'][$field_name][$langcode][$delta]['value']) ? $form_state['values'][$field_name][$langcode][$delta]['value'] : '';
     $pub_id = isset($form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id']) ? $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id'] : '';
     $uname = isset($form_state['values'][$field_name][$langcode][$delta]['uniquename']) ? $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
@@ -127,7 +112,7 @@ class schema__publication_widget extends ChadoFieldWidget {
     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.
@@ -136,6 +121,22 @@ class schema__publication_widget extends ChadoFieldWidget {
       $form_state['values'][$field_name][$langcode][$delta]['chado-' . $table_name . '__pub_id'] = '';
     }
   }
+
+  /**
+   * @see TripalFieldWidget::theme()
+   */
+  function theme($element) {
+
+    $layout = "
+      <div class=\"pub-widget\">
+        <div class=\"pub-widget-item\">" .
+          drupal_render($element['uniquename']) . "
+        </div>
+      </div>
+    ";
+
+    return $layout;
+  }
 }
 
 /**
@@ -148,26 +149,4 @@ function schema__publication_widget_form_ajax_callback($form, $form_state) {
 
   return $form[$field_name]['und'][$delta];
 }
-/**
- * Theme function for the pub widget.
- *
- * @param $variables
- */
-function theme_schema__publication_widget($variables) {
-  $element = $variables['element'];
-
-  // These two fields were added to the widget to help identify the fields
-  // for layout.
-  $table_name = $element['#table_name'];
-  $fkey = $element['#fkey_field'];
-
-  $layout = "
-      <div class=\"pub-widget\">
-        <div class=\"pub-widget-item\">" .
-        drupal_render($element['uniquename']) . "
-        </div>
-      </div>
-    ";
 
-        return $layout;
-}

+ 0 - 14
tripal_chado/includes/TripalFields/so__cds/so__cds_widget.inc

@@ -17,20 +17,6 @@ class so__cds_widget extends ChadoFieldWidget {
     // TODO: add a widget...
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
 
   /**
    *

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

@@ -56,15 +56,6 @@ class so__genotype extends ChadoField {
   protected $instance;
 
 
-  /**
-   *
-   * @see TripalField::validate()
-   */
-  public function validate($entity_type, $entity, $field, $items, &$errors) {
-
-  }
-
-
   /**
    *
    * @see TripalField::load()

+ 0 - 15
tripal_chado/includes/TripalFields/so__genotype/so__genotype_widget.inc

@@ -15,21 +15,6 @@ class so__genotype_widget extends ChadoFieldWidget {
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
-
   /**
    *
    * @see TripalFieldWidget::submit()

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

@@ -55,15 +55,6 @@ class so__transcript extends ChadoField {
   protected $instance;
 
 
-  /**
-   *
-   * @see TripalField::validate()
-   */
-  public function validate($entity_type, $entity, $field, $items, &$errors) {
-
-  }
-
-
   /**
    *
    * @see TripalField::load()

+ 0 - 15
tripal_chado/includes/TripalFields/so__transcript/so__transcript_widget.inc

@@ -15,21 +15,6 @@ class so__transcript_widget extends ChadoFieldWidget {
     parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
-
   /**
    *
    * @see TripalFieldWidget::submit()

+ 0 - 10
tripal_chado/includes/TripalFields/taxrank__infraspecific_taxon/taxrank__infraspecific_taxon.inc

@@ -54,16 +54,6 @@ class taxrank__infraspecific_taxon extends ChadoField {
   // when using the widgetForm, formatterSettingsForm, etc.) it should be set.
   protected $instance;
 
-
-  /**
-   *
-   * @see TripalField::validate()
-   */
-  public function validate($entity_type, $entity, $field, $items, &$errors) {
-
-  }
-
-
   /**
    *
    * @see TripalField::load()

+ 3 - 18
tripal_chado/includes/TripalFields/taxrank__infraspecific_taxon/taxrank__infraspecific_taxon_widget.inc

@@ -18,17 +18,17 @@ class taxrank__infraspecific_taxon_widget extends ChadoFieldWidget {
     $field_type = $this->field['type'];
     $field_table = $this->instance['settings']['chado_table'];
     $field_column = $this->instance['settings']['chado_column'];
-    
+
     $type_id = 0;
     if (count($items) > 0 and array_key_exists('organism__type_id', $items[0])) {
       $type_id = $items[0]['organism__type_id'];
     }
-    
+
     $form['value'] = array(
       '#type' => 'value',
       '#value' =>  array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
     );
-    
+
     $cv = tripal_get_default_cv($field_table, $field_column);
     $options = array();
     if ($cv) {
@@ -46,21 +46,6 @@ class taxrank__infraspecific_taxon_widget extends ChadoFieldWidget {
     );
   }
 
-  /**
-   * Performs validation of the widgetForm.
-   *
-   * 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 validate($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
-
-  }
-
-
   /**
    *
    * @see TripalFieldWidget::submit()

+ 108 - 81
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -400,7 +400,6 @@ function tripal_chado_field_storage_expand_field($item_name, $value) {
  */
 function tripal_chado_field_storage_query($query) {
 //print_r($query->fieldConditions);
-
   // The conditions and order bys are reorganized into a filters array for the
   // chado_select_record function()
   $filters = array();
@@ -421,89 +420,110 @@ function tripal_chado_field_storage_query($query) {
     $field_type = $field['type'];
     $field_module = $field['module'];
     $settings = $field['settings'];
-    $chado_table = $settings['chado_table'];
-    $chado_column = $settings['chado_column'];
 
-    // Set the value for this field search.
-    $subfields = explode('.', $column);
-    //print_r($subfields);
-    if (count($subfields) > 1) {
-      // Get the term for this field's column and replace the field_name with
-      // the term.  We need to do this for the recursive function to work.
-      // We must lowercase the term and underscore it because that's how we
-      // can support case-insensitivity and lack of spacing such as for
-      // web services.
-      $subfield1 = tripal_get_chado_semweb_term($chado_table, $chado_column, array('return_object' => TRUE));
-      $subfields[0] = strtolower(preg_replace('/ /', '_', $subfield1->name));
-      $value = tripal_chado_field_storage_recurse_subfilters($chado_table, $subfields, $value);
-      $value = array_shift($value);
-    }
-    else {
-      $value = $condition['value'];
-    }
+    // The Chado settings for a field are part of the instance and each bundle
+    // can have the same field but with different Chado mappings. Therefore,
+    // we need to iterate through the bundles to get the field instances.
+    $bundles = $field['bundles'];
+    foreach ($bundles['TripalEntity'] as $bundle_name) {
 
-    // Use the appropriate operator.
-    $operator = $condition['operator'] ? $condition['operator'] : '=';
-    switch ($operator) {
-      case '=':
-        $filters[$chado_table][$chado_column] = $value;
-        break;
-      case '>':
-      case '>=':
-      case '<':
-      case '<=':
-        $filters[$chado_table][$chado_column] = array(
-          'op' => $operator,
-          'data' => $value,
-        );
-        break;
-      case '<>':
-        $filters[$chado_table][$chado_column] = array(
-          'op' => '<>',
-          'data' => $value,
-        );
-        break;
-      case 'CONTAINS':
-        $filters[$chado_table][$chado_column] = array(
-          'op' => 'LIKE',
+      // If there is a bundle filter for the entity and if this bundle is not in
+      if (array_key_exists('bundle', $query->entityConditions)) {
+        if (strtolower($query->entityConditions['bundle']['operator']) == 'in' and
+            !array_key_exists($bundle_name, $query->entityConditions['bundle']['value'])) {
+          continue;
+        }
+        else if ($query->entityConditions['bundle']['value'] != $bundle_name) {
+          continue;
+        }
+      }
+
+      // Get the Chado mapping for this instance.
+      $instance = field_info_instance('TripalEntity', $field['field_name'], $bundle_name);
+      $chado_table = $instance['settings']['chado_table'];
+      $chado_column = $instance['settings']['chado_column'];
+
+      // Set the value for this field search.
+      $subfields = explode('.', $column);
+      //print_r($subfields);
+      if (count($subfields) > 1) {
+        // Get the term for this field's column and replace the field_name with
+        // the term.  We need to do this for the recursive function to work.
+        // We must lowercase the term and underscore it because that's how we
+        // can support case-insensitivity and lack of spacing such as for
+        // web services.
+        $subfield1 = tripal_get_chado_semweb_term($chado_table, $chado_column, array('return_object' => TRUE));
+        $subfields[0] = strtolower(preg_replace('/ /', '_', $subfield1->name));
+        $value = tripal_chado_field_storage_recurse_subfilters($chado_table, $subfields, $value);
+        $value = array_shift($value);
+      }
+      else {
+        $value = $condition['value'];
+      }
+
+      // Use the appropriate operator.
+      $operator = $condition['operator'] ? $condition['operator'] : '=';
+      switch ($operator) {
+        case '=':
+          $filters[$chado_table][$chado_column] = $value;
+          break;
+        case '>':
+        case '>=':
+        case '<':
+        case '<=':
+          $filters[$chado_table][$chado_column] = array(
+            'op' => $operator,
+            'data' => $value,
+          );
+          break;
+        case '<>':
+          $filters[$chado_table][$chado_column] = array(
+            'op' => '<>',
+            'data' => $value,
+          );
+          break;
+        case 'CONTAINS':
+          $filters[$chado_table][$chado_column] = array(
+            'op' => 'LIKE',
+            'data' => '%' . $value . '%',
+          );
+          break;
+        case 'NOT':
+          $filters[$chado_table][$chado_column] = array(
+          'op' => 'NOT LIKE',
           'data' => '%' . $value . '%',
-        );
-        break;
-      case 'NOT':
-        $filters[$chado_table][$chado_column] = array(
-        'op' => 'NOT LIKE',
-        'data' => '%' . $value . '%',
-        );
-        break;
-      case 'STARTS WITH':
-        $filters[$chado_table][$chado_column] = array(
-          'op' => 'LIKE',
+          );
+          break;
+        case 'STARTS WITH':
+          $filters[$chado_table][$chado_column] = array(
+            'op' => 'LIKE',
+            'data' => $value . '%',
+          );
+          break;
+        case 'NOT STARTS':
+          $filters[$chado_table][$chado_column] = array(
+          'op' => 'NOT LIKE',
           'data' => $value . '%',
-        );
-        break;
-      case 'NOT STARTS':
-        $filters[$chado_table][$chado_column] = array(
-        'op' => 'NOT LIKE',
-        'data' => $value . '%',
-        );
-        break;
-      case 'ENDS WITH':
-        $filters[$chado_table][$chado_column] = array(
-        'op' => 'LIKE',
-        'data' => '%' . $value,
-        );
-        break;
-      case 'NOT ENDS':
-        $filters[$chado_table][$chado_column] = array(
-        'op' => 'NOT LIKE',
-        'data' => '%' . $value,
-        );
-        break;
-      default:
-        // unrecognized operation.
-        break;
+          );
+          break;
+        case 'ENDS WITH':
+          $filters[$chado_table][$chado_column] = array(
+          'op' => 'LIKE',
+          'data' => '%' . $value,
+          );
+          break;
+        case 'NOT ENDS':
+          $filters[$chado_table][$chado_column] = array(
+          'op' => 'NOT LIKE',
+          'data' => '%' . $value,
+          );
+          break;
+        default:
+          // unrecognized operation.
+          break;
+      }
     }
-  }
+  } // end foreach ($query->fieldConditions as $index => $condition) {
 
   // Now get the list for sorting.
   foreach ($query->order as $index => $sort) {
@@ -524,8 +544,9 @@ function tripal_chado_field_storage_query($query) {
 
     $sorting[$chado_table][$chado_column] = $direction;
   }
+  //print_r($filters);
 
-  // Iterate through the filters and perform the query
+  // Iterate through the filters and perform the query.
   $entity_ids = array();
   foreach ($filters as $chado_table => $values) {
     //print_r($chado_table);
@@ -550,8 +571,14 @@ function tripal_chado_field_storage_query($query) {
       $select->condition('record_id', $record_ids);
       // If a bundle is specified then make sure we match on the bundle.
       if (array_key_exists('bundle', $query->entityConditions)) {
-        $select->condition('bundle', $query->entityConditions['bundle']);
+        if (strtolower($query->entityConditions['bundle']['operator']) == 'in') {
+          $select->condition('bundle', $query->entityConditions['bundle'], $operator);
+        }
+        else {
+          $select->condition('bundle', $query->entityConditions['bundle']);
+        }
       }
+
       $results = $select->execute();
       while ($result = $results->fetchObject()) {
         $entity_ids[] = array($result->entity_id, 0, $result->bundle);

+ 91 - 23
tripal_chado/includes/tripal_chado.publish.inc

@@ -2,29 +2,31 @@
 
 function tripal_chado_publish_form($form, &$form_state) {
 
-  $term_id = '';
+  global $language;
+  $langcode = $language->language;
+
+  $bundle_name = '';
   if (array_key_exists('values', $form_state)) {
-    $term_id = $form_state['values']['term_id'];
+    $bundle_name = $form_state['values']['bundle_name'];
   }
 
-
   $bundles = db_select('tripal_bundle', 'tb')
     ->fields('tb')
     ->orderBy('label', 'ASC')
     ->execute();
-  $term_ids = array();
-  $term_ids[] = 'Select a Content Type';
+  $bundle_ids = array();
+  $bundle_ids[] = 'Select a Content Type';
   while ($bundle = $bundles->fetchObject()) {
-    $term_ids[$bundle->term_id] = $bundle->label;
+    $bundle_ids[$bundle->name] = $bundle->label;
   }
 
-  $form['term_id'] = array(
+  $form['bundle_name'] = array(
     '#type' => 'select',
     '#title' => 'Content Type',
     '#description' => t('Select a content type to publish.  Only data that
       is mapped to the selected vocabulary term will be published.'),
-    '#options' => $term_ids,
-    '#default_value' => $term_id,
+    '#options' => $bundle_ids,
+    '#default_value' => $bundle_name,
     '#ajax' => array(
       'callback' => "tripal_chado_publish_form_ajax_callback",
       'wrapper' => "tripal-chado-publish-form",
@@ -35,7 +37,7 @@ function tripal_chado_publish_form($form, &$form_state) {
 
   // If the user has selected a content type, then we need to
   // show some filters.
-  if ($term_id) {
+  if ($bundle_name) {
     $form['filters'] = array(
       '#type' => 'fieldset',
       '#title' => 'Filters',
@@ -47,6 +49,62 @@ function tripal_chado_publish_form($form, &$form_state) {
       '#collapsible' => TRUE,
     );
 
+    // Get the list of fields and their widgets
+    $fields = field_info_field_map();
+    foreach ($fields as $field_name => $details) {
+      if (array_key_exists('TripalEntity', $details['bundles']) and
+          in_array($bundle_name, $details['bundles']['TripalEntity'])) {
+        $field = field_info_field($field_name);
+        $instance = field_info_instance('TripalEntity', $field_name, $bundle_name);
+
+
+        // Create a default element for this field.  This code
+        // is adapted from the field_multiple-value_form() function.
+        $title = check_plain($instance['label']);
+        $description = field_filter_xss($instance['description']);
+        $parents = $form['#parents'];
+        $multiple = $field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED;
+        $element = array(
+          '#entity_type' => $instance['entity_type'],
+          '#entity' => NULL,
+          '#bundle' => $instance['bundle'],
+          '#field_name' => $field_name,
+          '#language' => $langcode,
+          '#field_parents' => $parents,
+          '#columns' => array_keys($field['columns']),
+          '#title' =>  $title,
+          '#description' => $description,
+          '#required' => FALSE,
+          '#delta' => 0,
+        );
+
+        // Now call the widget callback function to let the module adjust the
+        // element as needed.
+        $function = $instance['widget']['module'] . '_field_widget_form';
+        $items = array();
+        $delta = 0;
+        $element = $function($form, $form_state, $field, $instance, $langcode, $items, $delta, $element);
+
+        // None of these fields are required, so turn off that setting.
+        $element['#required'] = FALSE;
+
+        $form['filters'][$field_name] =  array(
+          '#type' => 'container',
+          '#attributes' => array(
+            'class' => array(
+              'field-type-' . drupal_html_class($field['type']),
+              'field-name-' . drupal_html_class($field_name),
+              'field-widget-' . drupal_html_class($instance['widget']['type']),
+            ),
+          ),
+          '#weight' => $instance['widget']['weight'],
+          '#tree' => TRUE,
+          $langcode => array(
+            0 => $element
+          )
+        );
+      }
+    }
     $form['publish_btn'] = array(
       '#type' => 'submit',
       '#name' => 'publish_btn',
@@ -54,43 +112,53 @@ function tripal_chado_publish_form($form, &$form_state) {
     );
   }
 
-
   $form['#prefix'] = '<div id="tripal-chado-publish-form">';
   $form['#suffix'] = '</div>';
   return $form;
 }
 
 /**
- *
- * @param unknown $form
- * @param unknown $form_state
+ * Validate handler for the tripal_chado_publish_form form.
  */
 function tripal_chado_publish_form_validate($form, &$form_state) {
 
 }
 
 /**
- *
- * @param unknown $form
- * @param unknown $form_state
- * @return The
+ * Submit handler for the tripal_chado_publish_form form.
  */
 function tripal_chado_publish_form_submit($form, &$form_state) {
   if ($form_state['clicked_button']['#name'] == 'publish_btn') {
     global $user;
+    global $language;
+
+    $langcode = $language->language;
 
-    $term_id = $form_state['values']['term_id'];
-    $bundle_name = 'bio_data_' . $term_id;
+    $bundle_name = $form_state['values']['bundle_name'];
     $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
+
+    // Iterate through any filters and add those to the arguments
+    $filters = array();
+    $fields = field_info_field_map();
+    foreach ($fields as $field_name => $details) {
+      if (array_key_exists('TripalEntity', $details['bundles']) and
+          in_array($bundle_name, $details['bundles']['TripalEntity']) and
+          array_key_exists('value', $form_state['values'][$field_name][$langcode][0])) {
+        $value = $form_state['values'][$field_name][$langcode][0]['value'];
+        if ($value) {
+          $filters[$field_name] = $value;
+        }
+      }
+    }
     $args = array(
-      array('bundle_name' => $bundle_name),
+      array('bundle_name' => $bundle_name, 'filters' => $filters),
     );
     $includes = array(
       module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.publish'),
     );
     return tripal_add_job("Publish " . $bundle->label . " records.",
-      'tripal_chado', 'tripal_chado_publish_records', $args,
-      $user->uid, 10, $includes);
+       'tripal_chado', 'tripal_chado_publish_records', $args,
+       $user->uid, 10, $includes);
   }
 }
 /**

+ 8 - 8
tripal_chado/tripal_chado.module

@@ -595,18 +595,18 @@ function tripal_chado_theme($existing, $type, $theme, $path) {
        'render element' => 'element',
        'file' => 'includes/TripalFields/data__accession/data__accession_widget.inc',
      ),
-//     'chado_linker__dbxref_widget' => array(
-//       'render element' => 'element',
-//       'file' => 'includes/TripalFields/chado_linker__dbxref.inc',
-//     ),
+     'sbo__database_cross_reference_widget' => array(
+       'render element' => 'element',
+       'file' => 'includes/TripalFields/sbo__database_cross_reference/sbo__database_cross_reference_widget.inc',
+     ),
 //     'chado_linker__cvterm_widget' => array(
 //       'render element' => 'element',
 //       'file' => 'includes/TripalFields/chado_linker__cvterm.inc',
 //     ),
-//     'chado_linker__synonym_widget' => array(
-//       'render element' => 'element',
-//       'file' => 'includes/TripalFields/chado_linker__synonym.inc',
-//     ),
+     'schema__alternate_name_widget' => array(
+       'render element' => 'element',
+       'file' => 'includes/TripalFields/schema__alternate_name/schema__alternate_name_widget.inc',
+     ),
 //     'chado_linker__relationship_widget' => array(
 //       'render element' => 'element',
 //       'file' => 'includes/TripalFields/chado_linker__relationship.inc',

+ 0 - 1
tripal_chado/tripal_chado.views.inc

@@ -42,7 +42,6 @@ function tripal_chado_views_data_alter(&$data) {
  * for our storage engine.
  */
 function tripal_chado_add_field_views_data(&$data) {
-return;
   foreach (field_info_fields() as $field) {
     if ($field['storage']['type'] != 'field_chado_storage') {
       continue;

+ 9 - 4
tripal_ws/includes/tripal_ws.rest_v0.1.inc

@@ -324,25 +324,29 @@ function tripal_ws_services_v0_1_get_content_type($api_url, &$response, $ws_path
   $response['label'] = $bundle->label . " collection";
 
   // Iterate through the fields and create a $field_mapping array that makes
-  // it easier to determine which filter criteria belongs to which field.
+  // it easier to determine which filter criteria belongs to which field. The
+  // key is the label for the field and the value is the field name. This way
+  // user's can use the field label or the field name to form a query.
   $field_mapping = array();
   $fields = field_info_fields();
   foreach ($fields as $field) {
     if (array_key_exists('TripalEntity', $field['bundles'])) {
       foreach ($field['bundles']['TripalEntity'] as $bundle_name) {
         if ($bundle_name == $bundle->name) {
-          if (array_key_exists('semantic_web', $field['settings'])) {
-            list($vocabulary, $accession) = explode(':', $field['settings']['semantic_web']);
+          $instance = field_info_instance('TripalEntity', $field['field_name'], $bundle_name);
+          if (array_key_exists('term_accession', $instance['settings'])){
+            $vocabulary = $instance['settings']['term_vocabulary'];
+            $accession = $instance['settings']['term_accession'];
             $term = tripal_get_term_details($vocabulary, $accession);
             $key = $term['name'];
             $key = strtolower(preg_replace('/ /', '_', $key));
             $field_mapping[$key] = $field['field_name'];
+            $field_mapping[$field['field_name']] = $field['field_name'];
           }
         }
       }
     }
   }
-
   // Convert the filters to their field names
   $new_params = array();
   foreach ($params as $param => $value) {
@@ -425,6 +429,7 @@ function tripal_ws_services_v0_1_get_content_type($api_url, &$response, $ws_path
   $cquery = clone $query;
   $cquery->count();
   $num_records = $cquery->execute();
+
   if (!$num_records) {
     $num_records = 0;
   }

+ 1 - 1
tripal_ws/tripal_ws.module

@@ -123,7 +123,7 @@ function tripal_ws_services() {
     // TODO: What do we do if no version is provided?
   }
 
-  drupal_add_http_header('Content-Type', 'application/ld+json');
+  drupal_add_http_header('Content-Type', 'application/json');
   print drupal_json_encode($response);
 }