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

Fixed bugs form major rewrite of TripalField Class

Stephen Ficklin пре 8 година
родитељ
комит
232a0e31ee
24 измењених фајлова са 191 додато и 245 уклоњено
  1. 77 32
      tripal/includes/TripalField.inc
  2. 1 1
      tripal/includes/TripalFields/content_type.inc
  3. 12 13
      tripal/includes/tripal.fields.inc
  4. 1 1
      tripal_chado/includes/TripalFields/chado_base__dbxref_id.inc
  5. 3 3
      tripal_chado/includes/TripalFields/chado_base__organism_id.inc
  6. 1 1
      tripal_chado/includes/TripalFields/chado_feature__md5checksum.inc
  7. 1 1
      tripal_chado/includes/TripalFields/chado_feature__residues.inc
  8. 1 1
      tripal_chado/includes/TripalFields/chado_feature__seqlen.inc
  9. 1 1
      tripal_chado/includes/TripalFields/chado_gene__transcripts.inc
  10. 1 1
      tripal_chado/includes/TripalFields/chado_linker__contact.inc
  11. 1 1
      tripal_chado/includes/TripalFields/chado_linker__cvterm.inc
  12. 1 1
      tripal_chado/includes/TripalFields/chado_linker__cvterm_adder.inc
  13. 1 1
      tripal_chado/includes/TripalFields/chado_linker__dbxref.inc
  14. 1 1
      tripal_chado/includes/TripalFields/chado_linker__expression.inc
  15. 1 1
      tripal_chado/includes/TripalFields/chado_linker__featureloc.inc
  16. 1 1
      tripal_chado/includes/TripalFields/chado_linker__genotype.inc
  17. 1 1
      tripal_chado/includes/TripalFields/chado_linker__phenotype.inc
  18. 1 1
      tripal_chado/includes/TripalFields/chado_linker__prop.inc
  19. 1 1
      tripal_chado/includes/TripalFields/chado_linker__prop_adder.inc
  20. 1 1
      tripal_chado/includes/TripalFields/chado_linker__pub.inc
  21. 80 176
      tripal_chado/includes/TripalFields/chado_linker__relationship.inc
  22. 1 1
      tripal_chado/includes/TripalFields/chado_linker__synonym.inc
  23. 1 1
      tripal_chado/includes/TripalFields/chado_organism__type_id.inc
  24. 0 2
      tripal_chado/includes/tripal_chado.fields.inc

+ 77 - 32
tripal/includes/TripalField.inc

@@ -55,12 +55,17 @@ class TripalField {
   public static $default_description = 'The generic base class for all
        Tripal Fields. Replace this text as appropriate for the child implementation.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
-  // or the instanceSettingsForm() functions then you need to be sure that
-  // any settings you want those functions to manage are listed in this
-  // array.
+  // Provide a list of global settings. These can be accessed witihn the
+  // globalSettingsForm.  When the globalSettingsForm is submitted then
+  // Drupal will automatically change these settings for all fields.
   public static $default_settings = array();
 
+  // Provide a list of instance specific settings. These can be access within
+  // the instanceSettingsForm.  When the instanceSettingsForm is submitted
+  // then Drupal with automatically change these settings for the instnace.
+  // It is recommended to put settings at the instance level whenever possible.
+  public static $default_instance_settings  = array();
+
   // Set this to the name of the storage backend that by default will support
   // this field.
   public static $default_storage = 'tripal_no_storage';
@@ -115,7 +120,8 @@ class TripalField {
   /**
    * Provides default information about this field type
    *
-   * NOTE: this field should NOT be overridden by child classes.
+   * This function corresponds to the hook_field_info() function of
+   * the Drupal Field API.
    *
    * @return
    *   An array whose keys are field type names and whose values are arrays
@@ -130,6 +136,7 @@ class TripalField {
       'default_widget' => $field_type . '_widget',
       'default_formatter' => $field_type . '_formatter',
       'settings' => $field_type::$default_settings,
+      'instance_settings' => $field_type::$default_instance_settings,
       'storage' => array(
         'type' => $field_type::$default_storage,
         'module' => 'tripal',
@@ -141,6 +148,9 @@ class TripalField {
   /**
    * Provides information about the widgets provided by this field.
    *
+   * This function corresponds to the hook_field_widget_info() function of
+   * the Drupal Field API.
+   *
    * This is a static function as it provides default values for all of the
    * widgets for this field type, and thus we don't need an instantiated
    * object to provide this information.
@@ -162,6 +172,9 @@ class TripalField {
   /**
    * Provides information about the formatter for this field.
    *
+   * This function corresponds to the hook_field_formatter_info() function of
+   * the Drupal Field API.
+   *
    * This is a static function as it provides default values for all of the
    * formatters for this field type, and thus we don't need an instantiated
    * object to provide this information.
@@ -211,6 +224,9 @@ class TripalField {
   /**
    * Provides a summary of the formatter settings.
    *
+   * This function corresponds to the hook_field_formatter_settings_summary()
+   * function of the Drupal Field API.
+   *
    * On the 'Manage Display' page of the content type administration page,
    * fields are allowed to provide a settings form.  This settings form can
    * be used to allow the site admin to define how the field should be
@@ -239,6 +255,9 @@ class TripalField {
   /**
    * Provides the field's setting form.
    *
+   * This function corresponds to the hook_field_formatter_settings_form()
+   * function of the Drupal Field API.
+   *
    * The settings form appears on the 'Manage Display' page of the content
    * type administration page. This function provides the form that will
    * appear on that page.
@@ -266,6 +285,9 @@ class TripalField {
   /**
    *  Provides the display for a field
    *
+   * This function corresponds to the hook_field_formatter_view()
+   * function of the Drupal Field API.
+   *
    *  This function provides the display for a field when it is viewed on
    *  the web page.  The content returned by the formatter should only include
    *  what is present in the $items[$delta]['values] array. This way, the
@@ -276,8 +298,6 @@ class TripalField {
    *  @param $element
    *  @param $entity_type
    *  @param $entity
-   *  @param $field
-   *  @param $instance
    *  @param $langcode
    *  @param $items
    *  @param $display
@@ -299,6 +319,9 @@ class TripalField {
   /**
    * Provides the form for editing of this field.
    *
+   * This function corresponds to the hook_field_widget_form()
+   * function of the Drupal Field API.
+   *
    * This form is diplayed when the user creates a new entity or edits an
    * existing entity.  If the field is attached to the entity then the form
    * provided by this function will be displayed.
@@ -359,6 +382,9 @@ class TripalField {
   /**
    *  Perform validation of the widget_form when adding or editing the entity.
    *
+   *  This function corresponds to the hook_field_validate() function of the
+   *  Drupal Field API.
+   *
    *  Any errors encountered should be indicatd by adding a value to the $errors
    *  array according to the instructions below.
    *
@@ -389,15 +415,18 @@ class TripalField {
   }
 
   /**
-   *  Performs extra commands when the entity form is submitted.
+   * Performs extra commands when the entity form is submitted.
+   *
+   * This function corresponds to the hook_field_submit()
+   * function of the Drupal Field API.
    *
-   *  Drupal typically does not provide a submit hook for fields.  The
-   *  TripalField provides one to allow for behind-the-scenes actions to
-   *  occur.   This function should never be used for updates, deletes or
-   *  inserts into the storage backend. Rather, the appropriate Field Storage
-   *  implementation will take care of that. An example where this function
-   *  may be useful would be to set values in the $items array using values
-   *  of the other.
+   * Drupal typically does not provide a submit hook for fields.  The
+   * TripalField provides one to allow for behind-the-scenes actions to
+   * occur.   This function should never be used for updates, deletes or
+   * inserts into the storage backend. Rather, the appropriate Field Storage
+   * implementation will take care of that. An example where this function
+   * may be useful would be to set values in the $items array using values
+   * of the other.
    *
    *  @param $entity_type
    *    The type of $entity.
@@ -418,6 +447,7 @@ class TripalField {
    */
   public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
   }
+
   /**
    * Loads the field values from the underlying data store.
    *
@@ -451,20 +481,28 @@ class TripalField {
   }
 
   /**
-   * Provides a form for the 'Field Settings' of the field management page.
+   * Provides a form for the 'Field Settings' of an instance of this field.
    *
-   * This is an optional hook function and is similar to the
-   * hook_field_settings_form function().
+   * This function corresponds to the hook_field_instance_settings_form()
+   * function of the Drupal Field API.
    *
-   * @param $field
-   *   The field structure being configured.
-   * @param $instance
-   *   The instance structure being configured.
-   * @param $has_data
-   *   TRUE if the field already has data, FALSE if not.
+   * Validation of the instance settings form is not supported by Drupal, but
+   * the TripalField class does provide a mechanism for supporting validation.
+   * To allow for validation of your setting form you must call the parent
+   * in your child class:
+   *
+   * @code
+   *   $element = parent::instanceSettingsForm();
+   * @endcode
+   *
+   * Please note, the form generated with this function does not easily
+   * support AJAX calls in the same way that other Drupal forms do.  If you
+   * need to use AJAX you must manually alter the $form in your ajax call.
+   * The typical way to handle updating the form via an AJAX call is to make
+   * the changes in the form function itself but that doesn't work here.
    */
   public function instanceSettingsForm() {
-    $settings = $instance['settings'];
+    $settings = $this->instance['settings'];
     $element = array();
 
     //     $element['semantic_web'] = array(
@@ -479,16 +517,23 @@ class TripalField {
     //       '#collapsible' => TRUE,
     //       '#tree' => TRUE,
     //     );
-    $element['#field'] = $field;
-    $element['#instance'] = $instance;
+    //$element['#field'] = $this->field;
+    //$element['#instance'] = $this->instance;
     $element['#element_validate'][] = 'tripal_field_instance_settings_form_validate';
 
     return $element;
   }
   /**
+   * Provides validation of the instance settings form.
    *
-   * @param unknown $form
-   * @param unknown $form_state
+   * There is no equivalent function in the Drupal Field API. Validation
+   * of instance settings forms in Drupal is not supported. However, the
+   * TripalField provides this function to fill the gap.  See the
+   * documentation for the instanceSettingsForm() function for instructions
+   * to support use of this function.
+   *
+   * @param $form
+   * @param $form_state
    */
   public function instanceSettingsFormValidate($form, &$form_state) {
 
@@ -508,7 +553,7 @@ class TripalField {
    *   TRUE if the field already has data, FALSE if not.
    */
   public function globalSettingsForm($has_data) {
-    $settings = $field['settings'];
+    $settings = $this->field['settings'];
     $element = array();
 
 //     $element['semantic_web'] = array(
@@ -523,8 +568,8 @@ class TripalField {
 //       '#collapsible' => TRUE,
 //       '#tree' => TRUE,
 //     );
-    $element['#field'] = $field;
-    $element['#instance'] = $instance;
+//    $element['#field'] = $this->field;
+//    $element['#instance'] = $this->instance;
     $element['#element_validate'][] = 'tripal_field_settings_form_validate';
 
     return $element;

+ 1 - 1
tripal/includes/TripalFields/content_type.inc

@@ -8,7 +8,7 @@ class content_type extends TripalField {
   // The default description for this field.
   public static $default_description = 'The Tripal content type.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

+ 12 - 13
tripal/includes/tripal.fields.inc

@@ -218,7 +218,7 @@ function tripal_field_settings_form($field, $instance, $has_data) {
   $is_loaded = tripal_load_include_field_type($field_type);
   if ($is_loaded) {
     $tfield = new $field_type($field, $instance);
-    $form = $tfield->fieldSettingsForm($field, $instance, $has_data);
+    $form = $tfield->globalSettingsForm($field, $instance, $has_data);
   }
   return $form;
 }
@@ -235,42 +235,43 @@ function tripal_field_instance_settings_form($field, $instance) {
   }
   return $form;
 }
-
 /**
- * Implements hook_field_settings_form_validate().
+ * Implements hook_instance_settings_form_validate().
  *
  * This is not an actual Drpual hook, but rather a Tripal created hook
- * to alow the TripalField objects to have a fieldSettingsFormValidate()
+ * to alow the TripalField objects to have a instanceSettingsFormValidate()
  * member function.
  */
-function tripal_field_settings_form_validate($form, &$form_state) {
+function tripal_field_instance_settings_form_validate($form, &$form_state) {
   $field = $form['#field'];
   $instance = $form['#instance'];
   $field_type = $field['type'];
   $is_loaded = tripal_load_include_field_type($field_type);
   if ($is_loaded) {
     $tfield = new $field_type($field, $instance);
-    $form = $tfield->fieldSettingsFormValidate($field, $instance, $form, $form_state);
+    $form = $tfield->instanceSettingsFormValidate($field, $instance, $form, $form_state);
   }
 }
+
 /**
- * Implements hook_instance_settings_form_validate().
+ * Implements hook_field_settings_form_validate().
  *
  * This is not an actual Drpual hook, but rather a Tripal created hook
- * to alow the TripalField objects to have a instanceSettingsFormValidate()
+ * to alow the TripalField objects to have a globalSettingsFormValidate()
  * member function.
  */
-function tripal_instance_settings_form_validate($form, &$form_state) {
+function tripal_field_settings_form_validate($form, &$form_state) {
   $field = $form['#field'];
   $instance = $form['#instance'];
   $field_type = $field['type'];
   $is_loaded = tripal_load_include_field_type($field_type);
   if ($is_loaded) {
     $tfield = new $field_type($field, $instance);
-    $form = $tfield->instanceSettingsFormValidate($field, $instance, $form, $form_state);
+    $form = $tfield->globalSettingsFormValidate($field, $instance, $form, $form_state);
   }
 }
 
+
 /**
  * Implements hook_field_formatter_settings_summary().
  */
@@ -367,9 +368,7 @@ function tripal_field_validate($entity_type, $entity, $field, $instance,
   $is_loaded = tripal_load_include_field_type($field_type);
   if ($is_loaded) {
     $tfield = new $field_type($field, $instance);
-    $bundle = isset($entity->bundle) ? $entity->bundle : NULL;
-    $form = $field_type::widgetFormValidate($entity_type, $entity, $field, $instance,
-        $langcode, $items, $errors);
+    $tfield->widgetFormValidate($entity_type, $entity, $langcode, $items, $errors);
   }
 }
 

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

@@ -8,7 +8,7 @@ class chado_base__dbxref_id extends TripalField {
   public static $default_description = 'This field specifies the unique stable accession (ID) for
         this record. It requires that this site have a database entry.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -7,7 +7,7 @@ class chado_base__organism_id extends TripalField {
   // The default description for this field.
   public static $default_description = 'A field for specifying an organism.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.
@@ -247,8 +247,8 @@ class chado_base__organism_id extends TripalField {
   /**
    * @see TripalField::settings_form()
    */
-  public static function fieldSettingsForm($field, $instance, $has_data) {
-    $element = parent::fieldSettingsForm($field, $instance, $has_data);
+  public function globalSettingsForm($has_data) {
+    $element = parent::globalSettingsForm($has_data);
 
     $settings = $this->field['settings'];
 

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

@@ -7,7 +7,7 @@ class chado_feature__md5checksum  extends TripalField {
   // The default description for this field.
   public static $default_description = 'A field for generating MD5 checksum for a sequence.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -8,7 +8,7 @@ class chado_feature__residues extends TripalField {
   // The default description for this field.
   public static $default_description = 'A field for managing nucleotide and protein residues.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -7,7 +7,7 @@ class chado_feature__seqlen extends TripalField {
   // The default description for this field.
   public static $default_description = 'A field for calculating the length of a sequence.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -7,7 +7,7 @@ class chado_gene__transcripts extends TripalField {
   // The default description for this field.
   public static $default_description = 'Transcripts of genes.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -9,7 +9,7 @@ class chado_linker__contact extends TripalField {
   public static $default_description = 'Associates an indviddual or organization with
           this record';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -8,7 +8,7 @@ class chado_linker__cvterm extends TripalField {
   public static $default_description = 'This record can be annotated with terms
             from other vocabularies.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -8,7 +8,7 @@ class chado_linker__cvterm_adder extends TripalField {
   public static $default_description = 'This record may have any number of types of
         annotations. Use this field to first add the type.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -19,7 +19,7 @@ class chado_linker__dbxref extends TripalField {
           another online database. This field is intended for one or more
           references.  At a minimum, the database and accession must be provided.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -8,7 +8,7 @@ class chado_linker__expression extends TripalField {
   public static $default_description = 'Associates an expression with
           this record.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -8,7 +8,7 @@ class chado_linker__featureloc extends TripalField {
   // The default description for this field.
   public static $default_description = 'Locations on landmark sequences where the feature is aligned.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -8,7 +8,7 @@ class chado_linker__genotype extends TripalField {
   public static $default_description = 'Associates an indviddual or organization with
           this record.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -8,7 +8,7 @@ class chado_linker__phenotype extends TripalField {
   // The default description for this field.
   public static $default_description = 'Associates phenotypes with this record.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -7,7 +7,7 @@ class chado_linker__prop extends TripalField {
   // The default description for this field.
   public static $default_description = 'Add details about this property.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -8,7 +8,7 @@ class chado_linker__prop_adder extends TripalField {
   public static $default_description = 'This record may have any number of properties. Use
             this field to first add the type.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -9,7 +9,7 @@ class chado_linker__pub extends TripalField {
   public static $default_description = 'Associates a publication (e.g. journal article,
             conference proceedings, book chapter, etc.) with this record.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

+ 80 - 176
tripal_chado/includes/TripalFields/chado_linker__relationship.inc

@@ -7,7 +7,7 @@ class chado_linker__relationship extends TripalField {
   // The default description for this field.
   public static $default_description = 'Relationships between records.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.
@@ -18,140 +18,23 @@ class chado_linker__relationship extends TripalField {
     'semantic_web' => '',
   );
 
+  // Provide a list of instance specific settings. These can be access within
+  // the instanceSettingsForm.  When the instanceSettingsForm is submitted
+  // then Drupal with automatically change these settings for the instnace.
+  // It is recommended to put settings at the instance level whenever possible.
+  public static $default_instance_settings = array(
+    'relationships' => array(
+      'option1_vocabs' => '',
+      'option2_vocab' => '',
+      'option2_parent' => '',
+      'relationship_types' => '',
+    ),
+  );
+
   // Set this to the name of the storage backend that by default will support
   // this field.
   public static $default_storage = 'field_chado_storage';
 
-
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    $table_name = isset($this->details['chado_table']) ? $this->details['chado_table'] : '';
-    $type_table = isset($this->details['chado_type_table']) ? $this->details['chado_type_table'] : '';
-    $type_field = isset($this->details['chado_type_column']) ? $this->details['chado_type_column'] : '';
-    $cv_id      = isset($this->details['chado_cv_id']) ? $this->details['chado_cv_id'] : '';
-    $cvterm_id  = isset($this->details['chado_cvterm_id']) ? $this->details['chado_cvterm_id'] : '';
-
-    // If the linker table does not exists then we don't want to add attach.
-    $rel_table = $table_name . '_relationship';
-    if (chado_table_exists($rel_table)) {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $table_name = isset($this->details['chado_table']) ? $this->details['chado_table'] : '';
-    $type_table = isset($this->details['chado_type_table']) ? $this->details['chado_type_table'] : '';
-    $type_field = isset($this->details['chado_type_column']) ? $this->details['chado_type_column'] : '';
-    $cv_id      = isset($this->details['chado_cv_id']) ? $this->details['chado_cv_id'] : '';
-    $cvterm_id  = isset($this->details['chado_cvterm_id']) ? $this->details['chado_cvterm_id'] : '';
-
-    $this->field_name = $table_name . '_relationship';
-  }
-  /**
-   * @see TripalField::create_info()
-   */
-  function createInfo() {
-    if (!$this->can_attach) {
-      return;
-    }
-    $table_name = $this->details['chado_table'];
-    $type_table = $this->details['chado_type_table'];
-    $type_field = $this->details['chado_type_column'];
-    $cv_id      = $this->details['chado_cv_id'];
-    $cvterm_id  = $this->details['chado_cvterm_id'];
-
-    $rel_table = $table_name . '_relationship';
-    $schema = chado_get_schema($rel_table);
-    $pkey = $schema['primary key'][0];
-    return array(
-      'field_name' => $this->field_name,
-      'type' => 'chado_linker__relationship',
-      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
-      'locked' => FALSE,
-      'storage' => array(
-        'type' => 'field_chado_storage',
-      ),
-      'settings' => array(
-        'chado_table' => $rel_table,
-        'chado_column' => $pkey,
-        'base_table' => $table_name,
-        'semantic_web' => 'SBO:0000374',
-      ),
-    );
-  }
-  /**
-   * @see TripalField::createInstanceInfo()
-   */
-  function createInstanceInfo() {
-    if (!$this->can_attach) {
-      return;
-    }
-
-    $table_name = $this->details['chado_table'];
-    $type_table = $this->details['chado_type_table'];
-    $type_field = $this->details['chado_type_column'];
-    $cv_id      = $this->details['chado_cv_id'];
-    $cvterm_id  = $this->details['chado_cvterm_id'];
-
-    return array(
-      'field_name' => $this->field_name,
-      'entity_type' => $this->entity_type,
-      'bundle' => $this->bundle->name,
-      'label' => 'Relationships',
-      'description' => 'Other records with relationships to this record.',
-      'required' => FALSE,
-      'settings' => array(
-        'auto_attach' => FALSE,
-        'child_relationship_types' => '',
-        'relationship_types' => '',
-      ),
-      'widget' => array(
-        'type' => 'chado_linker__relationship_widget',
-        'settings' => array(
-          'display_label' => 1,
-        ),
-      ),
-      'display' => array(
-        'default' => array(
-          'label' => 'above',
-          'type' => 'chado_linker__relationship_formatter',
-          'settings' => array(),
-        ),
-      ),
-    );
-  }
-
-  /**
-   * @see TripalField::widgetInfo()
-   */
-  public static function widgetInfo() {
-    return array(
-      'chado_linker__relationship_widget' => array(
-        'label' => t('Relationship Settings'),
-        'field types' => array('chado_linker__relationship')
-      ),
-    );
-  }
-  /**
-   * @see TripalField::formatterInfo()
-   */
-  static function formatterInfo() {
-    return array(
-      'chado_linker__relationship_formatter' => array(
-        'label' => t('Relationships'),
-        'field types' => array('chado_linker__relationship'),
-        'settings' => array(
-        ),
-      ),
-    );
-  }
-
   /**
    * @see TripalField::formatterView()
    */
@@ -395,7 +278,7 @@ class chado_linker__relationship extends TripalField {
   /**
    * @see TripalField::validate()
    */
-  function validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
+  function widgetFormValidate($entity_type, $entity, $langcode, $items, &$errors) {
 
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
@@ -403,8 +286,6 @@ class chado_linker__relationship extends TripalField {
     $field_column = $this->field['settings']['chado_column'];
     $base_table = $this->field['settings']['base_table'];
 
-    $chado_record_id = $entity->chado_record_id;
-
     $schema = chado_get_schema($field_table);
     $fkeys = $schema['foreign keys'];
 
@@ -514,6 +395,7 @@ class chado_linker__relationship extends TripalField {
       }
 
       // Make sure that either our object or our subject refers to the base record.
+      $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' => 'chado_linker__relationship',
@@ -533,8 +415,7 @@ class chado_linker__relationship extends TripalField {
   /**
    * @see TripalField::submit()
    */
-  public function submit($entity_type, $entity, $field, $instance, $langcode,
-      &$items, $form, &$form_state) {
+  public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
 
     $field_name = $this->field['field_name'];
     $field_type = $this->field['type'];
@@ -872,6 +753,8 @@ class chado_linker__relationship extends TripalField {
   public function instanceSettingsForm() {
 
     $element = parent::instanceSettingsForm();
+
+    //$element = parent::instanceSettingsForm();
     $element['relationships'] = array(
       '#type' => 'fieldset',
       '#title' => 'Allowed Relationship Types',
@@ -905,7 +788,7 @@ class chado_linker__relationship extends TripalField {
       '#multiple' => TRUE,
       '#options' => $vocs,
       '#size' => 6,
-      '#default_value' => $this->instance['settings']['default_vocabs'],
+      '#default_value' => $this->instance['settings']['relationships']['option1_vocabs'],
       // TODO add ajax here so that the relationship autocomplete below works
     );
 
@@ -916,21 +799,28 @@ class chado_linker__relationship extends TripalField {
          heirarchy groups of related terms typically fall under a common parent. If you
          wish to limit the list of terms that a user can use for the relationship type,
          you can provide the parent term here.  Then, only that term\'s children will
-         then be avilable for use as a relationship type.',
+         be avilable for use as a relationship type.',
     );
     $element['relationships']['option2_vocab'] = array(
       '#type' => 'select',
-      '#description' => 'Specify Default Vocabularies',
+      '#description' => 'Specify Default Vocabulary',
       '#multiple' => FALSE,
       '#options' => $vocs,
-      '#default_value' => $this->instance['settings']['default_vocabs'],
-      // TODO add ajax here so that the relationship autocomplete below works
+      '#default_value' => $this->instance['settings']['relationships']['option2_vocab'],
+      '#ajax' => array(
+        'callback' => "chado_linker__relationship_instance_settings_form_ajax_callback",
+        'wrapper' => 'relationships-option2-parent',
+        'effect' => 'fade',
+        'method' => 'replace'
+      ),
     );
     $element['relationships']['option2_parent'] = array(
       '#type' => 'textfield',
       '#description' => 'Specify a Heirarchical Parent Term',
-      '#default_value' => $this->instance['settings']['child_relationship_types'],
-      '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/"
+      '#default_value' => $this->instance['settings']['relationships']['option2_parent'],
+      '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/",
+      '#prefix' => '<div id=relationships-option2-parent>',
+      '#suffix' => '</div>'
     );
     $element['relationships']['option3'] = array(
       '#type' => 'item',
@@ -940,7 +830,7 @@ class chado_linker__relationship extends TripalField {
     );
     $element['relationships']['relationship_types'] = array(
       '#type' => 'textarea',
-      '#default_value' => $this->instance['settings']['relationship_types'],
+      '#default_value' => $this->instance['settings']['relationships']['relationship_types'],
     );
 
     return $element;
@@ -951,37 +841,37 @@ class chado_linker__relationship extends TripalField {
    */
   public function instanceSettingsFormValidate($form, &$form_state) {
     //dpm($form);dpm($form_state);
-    $settings = $form_state['values']['instance']['settings'];
-
-    // Make sure the supplied types are valid cvterms
-    if (isset($settings['relationship_types'])) {
-      $rel_types = explode(PHP_EOL, $settings['relationship_types']);
-      foreach($rel_types AS $type) {
-        // Ignore empty lines
-        if (trim($type) == '') {
-          continue;
-        }
-        $term = tripal_get_cvterm(array('name' => trim($type)));
-        // Don't save the form  if a term can not be found or it matches more than one cvterm
-        if (!isset($term->cvterm_id)) {
-          form_set_error(
-            "instance][settings][relationships][relationship_types",
-            t("The term '@type' can not be found or matches more than one term.", array('@type' => $type))
-          );
-        }
-      }
-    }
-    // Make sure child relationship types are using a valid cvterm
-    if (isset($settings['child_relationship_types'])) {
-      $supertype = $settings['child_relationship_types'];
-      $term = tripal_get_cvterm(array('name' => trim($supertype)));
-      if (!isset($term->cvterm_id)) {
-        form_set_error(
-          "instance][settings][relationships][child_relationship_types",
-          t("The term '@type' can not be found or matches more than one term.", array('@type' => $supertype))
-        );
-      }
-    }
+//     $settings = $form_state['values']['instance']['settings'];
+
+//     // Make sure the supplied types are valid cvterms
+//     if (isset($settings['relationship_types'])) {
+//       $rel_types = explode(PHP_EOL, $settings['relationship_types']);
+//       foreach($rel_types AS $type) {
+//         // Ignore empty lines
+//         if (trim($type) == '') {
+//           continue;
+//         }
+//         $term = tripal_get_cvterm(array('name' => trim($type)));
+//         // Don't save the form  if a term can not be found or it matches more than one cvterm
+//         if (!isset($term->cvterm_id)) {
+//           form_set_error(
+//             "instance][settings][relationships][relationship_types",
+//             t("The term '@type' can not be found or matches more than one term.", array('@type' => $type))
+//           );
+//         }
+//       }
+//     }
+//     // Make sure child relationship types are using a valid cvterm
+//     if (isset($settings['child_relationship_types'])) {
+//       $supertype = $settings['child_relationship_types'];
+//       $term = tripal_get_cvterm(array('name' => trim($supertype)));
+//       if (!isset($term->cvterm_id)) {
+//         form_set_error(
+//           "instance][settings][relationships][child_relationship_types",
+//           t("The term '@type' can not be found or matches more than one term.", array('@type' => $supertype))
+//         );
+//       }
+//     }
   }
 }
 
@@ -1015,9 +905,10 @@ function theme_chado_linker__relationship_widget($variables) {
 }
 
 /**
- * An Ajax callback for the dbxref widget.
+ * An Ajax callback for the relationshp widget.
  */
 function chado_linker__relationship_widget_form_ajax_callback(&$form, $form_state) {
+
   // Get the triggering element
   $form_element_name = $form_state['triggering_element']['#name'];
   preg_match('/(.+?)\[(.+?)\]\[(.+?)\]/', $form_element_name, $matches);
@@ -1034,4 +925,17 @@ function chado_linker__relationship_widget_form_ajax_callback(&$form, $form_stat
   }
 }
 
+/**
+ * An Ajax callback for the relationshp instance setting form.
+ */
+function chado_linker__relationship_instance_settings_form_ajax_callback(&$form, $form_state) {
+  $acpath  = $form['instance']['settings']['relationships']['option2_parent']['#autocomplete_path'];
+  $acpath .=  $form_state['values']['instance']['settings']['relationships']['option2_vocab'] . '/';
+  $urlval  = $form['instance']['settings']['relationships']['option2_parent']['#autocomplete_input']['#url_value'];
+  $urlval .=  $form_state['values']['instance']['settings']['relationships']['option2_vocab'];
+
+  $form['instance']['settings']['relationships']['option2_parent']['#autocomplete_path'] = $acpath;
+  $form['instance']['settings']['relationships']['option2_parent']['#autocomplete_input']['#url_value'] = $urlval;
+  return $form['instance']['settings']['relationships']['option2_parent'];
+}
 

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

@@ -8,7 +8,7 @@ class chado_linker__synonym extends TripalField {
   // The default description for this field.
   public static $default_description = 'Adds an alternative name (synonym or alias) to this record.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

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

@@ -8,7 +8,7 @@ class chado_organism__type_id extends TripalField {
   // The default description for this field.
   public static $default_description = 'Specifies the infraspecific type of an organism.';
 
-  // Add any default settings elements.  If you override the fieldSettingsForm()
+  // Add any default settings elements.  If you override the globalSettingsForm()
   // or the instanceSettingsForm() functions then you need to be sure that
   // any settings you want those functions to manage are listed in this
   // array.

+ 0 - 2
tripal_chado/includes/tripal_chado.fields.inc

@@ -1321,8 +1321,6 @@ function tripal_chado_create_tripalfield_instance_linker(&$info, $entity_type, $
       'required' => FALSE,
       'settings' => array(
         'auto_attach' => FALSE,
-        'child_relationship_types' => '',
-        'relationship_types' => '',
       ),
       'widget' => array(
         'type' => 'chado_linker__relationship_widget',