Browse Source

Working on TripalField redo

Stephen Ficklin 8 years ago
parent
commit
16e680ac6c
28 changed files with 1471 additions and 1829 deletions
  1. 11 7
      tripal/api/tripal.entities.api.inc
  2. 31 38
      tripal/api/tripal.fields.api.inc
  3. 10 30
      tripal/includes/TripalField.inc
  4. 58 0
      tripal/includes/TripalFields/content_type.inc
  5. 0 153
      tripal/includes/fields/content_type.inc
  6. 300 83
      tripal/includes/tripal.fields.inc
  7. 91 125
      tripal_chado/includes/TripalFields/chado_base__dbxref_id.inc
  8. 21 65
      tripal_chado/includes/TripalFields/chado_base__organism_id.inc
  9. 21 47
      tripal_chado/includes/TripalFields/chado_feature__md5checksum.inc
  10. 21 35
      tripal_chado/includes/TripalFields/chado_feature__residues.inc
  11. 20 47
      tripal_chado/includes/TripalFields/chado_feature__seqlen.inc
  12. 20 48
      tripal_chado/includes/TripalFields/chado_gene__transcripts.inc
  13. 20 46
      tripal_chado/includes/TripalFields/chado_linker__contact.inc
  14. 22 25
      tripal_chado/includes/TripalFields/chado_linker__cvterm.inc
  15. 18 48
      tripal_chado/includes/TripalFields/chado_linker__cvterm_adder.inc
  16. 22 49
      tripal_chado/includes/TripalFields/chado_linker__dbxref.inc
  17. 20 47
      tripal_chado/includes/TripalFields/chado_linker__expression.inc
  18. 20 46
      tripal_chado/includes/TripalFields/chado_linker__featureloc.inc
  19. 21 73
      tripal_chado/includes/TripalFields/chado_linker__genotype.inc
  20. 20 72
      tripal_chado/includes/TripalFields/chado_linker__phenotype.inc
  21. 20 69
      tripal_chado/includes/TripalFields/chado_linker__prop.inc
  22. 21 48
      tripal_chado/includes/TripalFields/chado_linker__prop_adder.inc
  23. 21 46
      tripal_chado/includes/TripalFields/chado_linker__pub.inc
  24. 21 18
      tripal_chado/includes/TripalFields/chado_linker__relationship.inc
  25. 20 46
      tripal_chado/includes/TripalFields/chado_linker__synonym.inc
  26. 20 50
      tripal_chado/includes/TripalFields/chado_organism__type_id.inc
  27. 574 461
      tripal_chado/includes/tripal_chado.fields.inc
  28. 7 7
      tripal_chado/tripal_chado.module

+ 11 - 7
tripal/api/tripal.entities.api.inc

@@ -243,20 +243,22 @@ function tripal_create_bundle($vocabulary, $accession, $term_name, &$error = '')
     // Get the bundle object.
     $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
 
-    // Get the list of fields to create.
-    foreach (module_implements('field_create_info') as $module) {
-      $function = $module . '_field_create_info';
+    // Get the list of fields created by Tripal modules and
+    // create them if they don't already exist.
+    foreach (module_implements('create_tripalfields') as $module) {
+      $function = $module . '_create_tripalfields';
       if (function_exists($function)) {
         $fields = $function('TripalEntity', $bundle);
         if (!$fields){
           continue;
         }
-        foreach ($fields as $field_name => $info) {
+        foreach ($fields as $info) {
           // If the field already exists then skip it.
           $field = field_info_field($info['field_name']);
           if ($field) {
             continue;
           }
+          dpm($info);
           $field = field_create_field($info);
           if (!$field) {
             tripal_set_message(t("Could not create new field: %field.",
@@ -267,14 +269,14 @@ function tripal_create_bundle($vocabulary, $accession, $term_name, &$error = '')
     }
 
     // Now get the list of field instances to add to the bundle.
-    foreach (module_implements('field_create_instance_info') as $module) {
-      $function = $module . '_field_create_instance_info';
+    foreach (module_implements('create_tripalfield_instance') as $module) {
+      $function = $module . '_create_tripalfield_instance';
       if (function_exists($function)) {
         $fields = $function('TripalEntity', $bundle);
         if (!$fields){
           continue;
         }
-        foreach ($fields as $field_name => $info) {
+        foreach ($fields as $info) {
           // If the field is already attached to this bundle then skip it.
           $field = field_info_field($info['field_name']);
           if ($field and array_key_exists('bundles', $field) and
@@ -282,6 +284,7 @@ function tripal_create_bundle($vocabulary, $accession, $term_name, &$error = '')
               in_array($bundle_name, $field['bundles']['TripalEntity'])) {
             continue;
           }
+          dpm($info);
           $instance = field_create_instance($info);
         }
       }
@@ -290,6 +293,7 @@ function tripal_create_bundle($vocabulary, $accession, $term_name, &$error = '')
   catch (Exception $e) {
     $transaction->rollback();
     $error = _drupal_decode_exception($e);
+    dpm($info);
     drupal_set_message(t("Failed to create content type': %message",
         array('%message' => $error['!message'])), 'error');
     return FALSE;

+ 31 - 38
tripal/api/tripal.fields.api.inc

@@ -89,54 +89,47 @@ function tripal_get_fields($module, $entity_type, $bundle, $details = array()) {
  * @return
  *   A list of TripalField field type.
  */
-function tripal_get_field_types($module) {
+function tripal_get_field_types() {
   $types = array();
 
-  // Find all of the files in the tripal_chado/includes/fields directory.
-  $fields_path = drupal_get_path('module', $module) . '/includes/fields';
-  $field_files = file_scan_directory($fields_path, '/.*\.inc$/');
-
-  // Iterate through the fields, include the file and run the info function.
-  foreach ($field_files as $file) {
-    $field_type = $file->name;
-    module_load_include('inc', $module, 'includes/fields/' . $field_type);
-    if (class_exists($field_type)) {
-      $types[] = $field_type;
+  $modules = module_list(TRUE);
+  foreach ($modules as $module) {
+    // Find all of the files in the tripal_chado/includes/fields directory.
+    $fields_path = drupal_get_path('module', $module) . '/includes/TripalFields';
+    $field_files = file_scan_directory($fields_path, '/.*\.inc$/');
+    // Iterate through the fields, include the file and run the info function.
+    foreach ($field_files as $file) {
+      $field_type = $file->name;
+      module_load_include('inc', $module, 'includes/TripalFields/' . $field_type);
+      if (class_exists($field_type)) {
+        $types[] = $field_type;
+      }
     }
   }
-
   return $types;
 }
 /**
- * Retreives an intance of a TripalField class.
- *
- * The TripalField classes can be added by a site developer and should be
- * placed in the [module]/includes/fields directory.  Tripal will support
- * any field as long as it is in this directory and extends the TripalField
- * class.  To support dynamic inclusion of new fields this function
- * serves as a wrapper for locating the appropriate class file and
- * instantiating the object.
+ * Loads the TripalField class file into scope.
  *
  * @param $field_type
  *   The type of field to instantiate
- * @param $module
- *   The module that provides this field.
- * @param $entity_type
- *   The type of entity (e.g. TripalEntity).
- * @param $bundle
- *   The bundle object.  This is the bundle that is being offered
- *   to the field for attachement. The function will determine if this
- *   field should be attached to this bundle.
- * @param $details
- *   An array of additional "details" that are required by the modue that
- *   implements this field. For example, an associative array of values
- *   needed for the field to work properly.
+ *
+ * @return
+ *   TRUE if the field type class file was found, FALSE otherwise.
  */
-function tripal_get_field($field_type, $module, $entity_type, $bundle, $details = array()) {
+function tripal_load_include_field_type($field_type) {
 
-  module_load_include('inc', $module, 'includes/fields/' . $field_type);
-  if (class_exists($field_type)) {
-    return new $field_type($entity_type, $bundle, $details);
+  $modules = module_list(TRUE);
+  foreach ($modules as $module) {
+    $file_path = drupal_get_path('module', $module) . '/includes/TripalFields/' . $field_type;
+    if (file_exists($file_path)) {
+      module_load_include('inc', $module, 'includes/fields/' . $field_type);
+      if (class_exists($field_type)) {
+        return TRUE;
+      }
+    }
   }
-  return NULL;
-}
+  return FALSE;
+}
+
+

+ 10 - 30
tripal/includes/TripalField.inc

@@ -2,7 +2,7 @@
 
 
 /**
- * A base class for all fields supported by Tripal.
+ * A base class for fields attached to Tripal Entities.
  *
  * The Field API of Drupal defines three "levels" for fields:  field types,
  * fields, and instances of fields. This class attempts to consolidate use
@@ -67,10 +67,7 @@ class TripalField {
 
   // Set this to the name of the storage backend that by default will support
   // this field.
-  public static $default_storage = 'tripal';
-
-  // Set this to be the name of the module that is responsible for this field.
-  public static $module = 'tripal';
+  public static $default_storage = 'tripal_no_storage';
 
 
 
@@ -136,13 +133,13 @@ class TripalField {
   public static function globalInfo() {
     $field_type = get_called_class();
     return array(
-      'label' => self::$default_label,
-      'description' => self::$default_description,
+      'label' => $field_type::$default_label,
+      'description' => $field_type::$default_description,
       'default_widget' => $field_type . '_widget',
       'default_formatter' => $field_type . '_formatter',
-      'settings' => self::$default_settings,
+      'settings' => $field_type::$default_settings,
       'storage' => array(
-        'type' => self::$default_storage,
+        'type' => $field_type::$default_storage,
         'module' => 'tripal',
         'active' => TRUE
       ),
@@ -164,7 +161,7 @@ class TripalField {
     $field_type = get_called_class();
     return array(
       $field_type . '_widget' => array(
-        'label' => self::$default_label,
+        'label' => $field_type::$default_label,
         'field types' => array($field_type)
       ),
     );
@@ -186,7 +183,7 @@ class TripalField {
     $field_type = get_called_class();
     return array(
       $field_type . '_formatter' => array(
-        'label' => self::$default_label,
+        'label' => $field_type::$default_label,
         'field types' => array($field_type),
         'settings' => array(),
       ),
@@ -215,21 +212,6 @@ class TripalField {
   // Child classes SHOULD NOT override these functions as needed.
   // --------------------------------------------------------------------------
 
-  /**
-   * Creates an instance of a field and attaches it to a bundle.
-   *
-   * Typically there is no reason for a child class to override this function.
-   *
-   * @param $info
-   */
-  public function createInstance($info = array()) {
-    //if ($this->canAttach($info['entity_type'], $info['bundle'])) {
-      return field_create_instance($info);
-    //}
-    //else {
-    //  return FALSE;
-    //}
-  }
 
   // --------------------------------------------------------------------------
   //                  OVERRIDEABLE FIELD SPECIFIC FUNCTIONS
@@ -544,10 +526,9 @@ class TripalField {
     //       '#collapsible' => TRUE,
     //       '#tree' => TRUE,
     //     );
-    $module = $field['module'];
     $element['#field'] = $field;
     $element['#instance'] = $instance;
-    $element['#element_validate'][] = $module . '_field_instance_settings_form_validate';
+    $element['#element_validate'][] = 'tripal_field_instance_settings_form_validate';
 
     return $element;
   }
@@ -589,10 +570,9 @@ class TripalField {
 //       '#collapsible' => TRUE,
 //       '#tree' => TRUE,
 //     );
-    $module = $field['module'];
     $element['#field'] = $field;
     $element['#instance'] = $instance;
-    $element['#element_validate'][] = $module . '_field_settings_form_validate';
+    $element['#element_validate'][] = 'tripal_field_settings_form_validate';
 
     return $element;
   }

+ 58 - 0
tripal/includes/TripalFields/content_type.inc

@@ -0,0 +1,58 @@
+<?php
+
+class content_type extends TripalField {
+
+  // The default lable for this field.
+  public static $default_label = 'Content Type';
+
+  // The default description for this field.
+  public static $default_description = 'The Tripal content type.';
+
+  // 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.
+  public static $default_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';
+
+
+  /**
+   * @see TripalField::load()
+   */
+  static function load($field, $entity, $details = array()) {
+    $bundle = tripal_load_bundle_entity(array('name' => $entity->bundle));
+    $entity->{$field['field_name']}['und'][0]['value'] = $bundle->label;
+  }
+
+  /**
+   * @see TripalField::formatterView()
+   */
+  static function formatterView(&$element, $entity_type, $entity,
+      $field, $instance, $langcode, $items, $display) {
+
+    foreach ($items as $delta => $item) {
+      $element[$delta] = array(
+        '#type' => 'markup',
+        '#markup' => $item['value'],
+      );
+    }
+  }
+
+  /**
+   * @see TripalField::widgetForm()
+   */
+  static function widgetForm(&$widget, &$form, &$form_state, $field, $instance,
+      $langcode, $items, $delta, $element) {
+
+    $widget = $element;
+    switch ($instance['widget']['type']) {
+      case 'tripal_content_type_widget':
+        // There is no widget for this type.
+        break;
+    }
+  }
+
+}

+ 0 - 153
tripal/includes/fields/content_type.inc

@@ -1,153 +0,0 @@
-<?php
-
-class content_type extends TripalField {
-
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $this->field_name = 'content_type';
-  }
-
-  /**
-   * @see TripalField::setCanAttach()
-   */
-  protected function setCanAttach() {
-    // We always attach to TriplEntity entities.
-    if ($this->entity_type == 'TripalEntity') {
-      $this->can_attach = TRUE;
-    }
-  }
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  static function fieldDefaults() {
-    return array(
-      'label' => t('Record Type'),
-      'description' => t('The content type.'),
-      'default_widget' => 'tripal_content_type_widget',
-      'default_formatter' => 'tripal_content_type_formatter',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'tripal_no_storage',
-        'module' => 'tripal',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::createFieldInfo()
-   */
-  public function createInfo() {
-    if (!$this->can_attach) {
-      return;
-    }
-
-    return array(
-      'field_name' => $this->field_name,
-      'type' => 'content_type',
-      'cardinality' => 1,
-      'locked' => FALSE,
-      'storage' => array(
-        'type' => 'tripal_no_storage'
-      ),
-      'settings' => array(
-        'semantic_web' => 'rdfs:type',
-      ),
-    );
-  }
-  /**
-   * @see TripalField::createInstanceInfo()
-   */
-  public function createInstanceInfo() {
-
-    if (!$this->can_attach) {
-      return;
-    }
-
-    return array(
-      'field_name' => $this->field_name,
-      'entity_type' => 'TripalEntity',
-      'bundle' => $this->bundle->name,
-      'label' => 'Resource Type',
-      'description' => '',
-      'required' => FALSE,
-      'settings' => array(
-        'auto_attach' => TRUE,
-      ),
-      'widget' => array(
-        'type' => 'tripal_content_type_widget',
-        'settings' => array(
-          'display_label' => 1,
-        ),
-      ),
-      'display' => array(
-        'default' => array(
-          'label' => 'inline',
-          'type' => 'tripal_content_type_formatter',
-          'settings' => array(),
-        ),
-      ),
-    );
-  }
-  /**
-   * @see TripalField::widgetInfo()
-   */
-  static function widgetInfo() {
-    return array(
-      'tripal_content_type_widget' => array(
-        'label' => t('Record Type'),
-        'field types' => array('content_type')
-      ),
-    );
-  }
-  /**
-   * @see TripalField::formatterInfo()
-   */
-  static function formatterInfo() {
-    return array(
-      'tripal_content_type_formatter' => array(
-        'label' => t('Record Type'),
-        'field types' => array('content_type')
-      ),
-    );
-  }
-
-  /**
-   * @see TripalField::load()
-   */
-  static function load($field, $entity, $details = array()) {
-
-    $bundle = tripal_load_bundle_entity(array('name' => $entity->bundle));
-    $entity->{$field['field_name']}['und'][0]['value'] = $bundle->label;
-  }
-
-  /**
-   * @see TripalField::formatterView()
-   */
-  static function formatterView(&$element, $entity_type, $entity,
-      $field, $instance, $langcode, $items, $display) {
-
-    foreach ($items as $delta => $item) {
-      $element[$delta] = array(
-        '#type' => 'markup',
-        '#markup' => $item['value'],
-      );
-    }
-  }
-  /**
-   * @see TripalField::widgetForm()
-   */
-  static function widgetForm(&$widget, &$form, &$form_state, $field, $instance,
-      $langcode, $items, $delta, $element) {
-
-    $widget = $element;
-    switch ($instance['widget']['type']) {
-      case 'tripal_content_type_widget':
-        // There is no widget for this type.
-        break;
-    }
-
-  }
-
-}

+ 300 - 83
tripal/includes/tripal.fields.inc

@@ -12,72 +12,20 @@
 function tripal_field_info() {
 
   $info = array();
-
-  $modules = module_list();
-  foreach ($modules as $module) {
-    $field_types = tripal_get_field_types($module);
-    foreach ($field_types as $field_type) {
-      $info[$field_type] = $field_type::globalInfo();
-    }
-  }
-  return $info;
-}
-
-/**
- * Creates TripalField fields.
- *
- *
- */
-function tripal_create_tripal_fields() {
-  $info = tripal_field_info();
-  foreach ($info as $field_type => $info) {
-    $field_info = $field_type::fieldInfo();
-  }
-}
-
-/**
- * Implements hook_field_create_info().
- *
- * This is a Tripal defined hook that supports integration with the
- * TripalEntity field.
- */
-function tripal_field_create_info($entity_type, $bundle) {
-
-  $info = array();
-  $fields = tripal_get_fields('tripal', $entity_type, $bundle);
-  foreach ($fields as $field) {
-    $field_name = $field->getFieldName();
-    if ($field->canAttach()) {
-      $info[$field_name] = $field->createInfo();
-    }
+  $field_types = tripal_get_field_types();
+  foreach ($field_types as $field_type) {
+    $info[$field_type] = $field_type::globalInfo();
   }
   return $info;
 }
 
-/**
- * Implements hook_create_instance_info().
- *
- * This is a Tripal defined hook that supports integration with the
- * TripalEntity field.
- */
-function tripal_field_create_instance_info($entity_type, $bundle) {
-  $info = array();
-  $fields = tripal_get_fields('tripal', $entity_type, $bundle);
-  foreach ($fields as $field) {
-    $field_name = $field->getFieldName();
-    if ($field->canAttach()) {
-      $info[$field_name] = $field->createInstanceInfo();
-    }
-  }
-  return $info;
-}
 /**
  * Implements hook_field_widget_info();
  */
 function tripal_field_widget_info() {
   $info = array();
 
-  $field_types = tripal_get_field_types('tripal');
+  $field_types = tripal_get_field_types();
   foreach ($field_types as $field_type) {
     $info += $field_type::widgetInfo();
   }
@@ -90,13 +38,68 @@ function tripal_field_widget_info() {
 function tripal_field_formatter_info() {
   $info = array();
 
-  $field_types = tripal_get_field_types('tripal');
+  $field_types = tripal_get_field_types();
   foreach ($field_types as $field_type) {
     $info += $field_type::formatterInfo();
   }
   return $info;
 }
 
+/**
+ *
+ */
+function tripal_create_tripalfields($entity_type, $bundle) {
+  $field_name = 'content_type';
+  $info = array();
+  $info[] = array(
+    'field_name' => $field_name,
+    'type' => 'content_type',
+    'cardinality' => 1,
+    'locked' => FALSE,
+    'storage' => array(
+      'type' => 'tripal_no_storage'
+    ),
+    'settings' => array(
+      'semantic_web' => 'rdfs:type',
+    ),
+  );
+  return $info;
+}
+
+/**
+ *
+ * @param unknown $entity_type
+ * @param unknown $bundle
+ */
+function tripal_create_tripalfield_instance($entity_type, $bundle) {
+  $field_name = 'content_type';
+  $info = array();
+  $info[] = array(
+    'field_name' => $field_name,
+    'entity_type' => 'TripalEntity',
+    'bundle' => $this->bundle->name,
+    'label' => 'Resource Type',
+    'description' => '',
+    'required' => FALSE,
+    'settings' => array(
+      'auto_attach' => TRUE,
+    ),
+    'widget' => array(
+      'type' => 'tripal_content_type_widget',
+      'settings' => array(
+        'display_label' => 1,
+      ),
+    ),
+    'display' => array(
+      'default' => array(
+        'label' => 'inline',
+        'type' => 'tripal_content_type_formatter',
+        'settings' => array(),
+      ),
+    ),
+  );
+  return $info;
+}
 /**
  * Implements hook_field_formatter_view().
  */
@@ -105,34 +108,14 @@ function tripal_field_formatter_view($entity_type, $entity, $field,
 
   $element = array();
   $field_type = $field['type'];
-  module_load_include('inc', 'tripal', 'includes/fields/' . $field_type);
-  if (class_exists($field_type)) {
-    $field_obj = new $field_type($entity_type, $entity->bundle);
-    $field_obj::formatterView($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display);
+  $is_loaded = tripal_load_include_field_type($field_type);
+  if ($is_loaded) {
+    $tfield = new $field_type(array('field' => $field));
+    $tfield->formatterView($element, $entity_type, $entity, $field,
+        $instance, $langcode, $items, $display);
   }
   return $element;
 }
-/**
- * Implements hook_field_is_empty().
- */
-function tripal_field_is_empty($item, $field) {
-
-  // If there is no value field then the field is empty.
-  if (!array_key_exists('value', $item)) {
-    return TRUE;
-  }
-
-  // Iterate through all of the fields and if at least one has a value
-  // the field is not empty.
-  foreach ($item as $form_field_name => $value) {
-    if (isset($value) and $value != NULL and $value != '') {
-      return FALSE;
-    }
-  }
-
-  // Otherwise, the field is empty.
-  return TRUE;
-}
 
 /**
  * Simple provides a message indicating that the field cannot be deleted.
@@ -223,4 +206,238 @@ function tripal_form_field_ui_field_overview_form_alter(&$form, &$form_state, $f
       want all biological content to be stored in Chado, be sure that the
       respective fields are "supported by" Chado.',
   );
-}
+}
+
+
+
+/**
+ * Implements hook_field_settings_form()
+ */
+function tripal_field_settings_form($field, $instance, $has_data) {
+  $form = array();
+  $field_type = $field['type'];
+  $is_loaded = tripal_load_include_field_type($field_type);
+  if ($is_loaded) {
+    $tfield = new $field_type(array('field' => $field));
+    $form = $tfield->fieldSettingsForm($field, $instance, $has_data);
+  }
+  return $form;
+}
+/**
+ * Implements hook_instance_settings_form()
+ */
+function tripal_field_instance_settings_form($field, $instance) {
+  $form = array();
+  $field_type = $field['type'];
+  $is_loaded = tripal_load_include_field_type($field_type);
+  if ($is_loaded) {
+    $tfield = new $field_type(array('field' => $field));
+    $form = $tfield->instanceSettingsForm($field, $instance);
+  }
+  return $form;
+}
+
+/**
+ * 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 fieldSettingsFormValidate()
+ * member function.
+ */
+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(array('field' => $field));
+    $form = $tfield->fieldSettingsFormValidate($field, $instance, $form, $form_state);
+  }
+}
+/**
+ * Implements hook_instance_settings_form_validate().
+ *
+ * This is not an actual Drpual hook, but rather a Tripal created hook
+ * to alow the TripalField objects to have a instanceSettingsFormValidate()
+ * member function.
+ */
+function tripal_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(array('field' => $field));
+    $form = $tfield->instanceSettingsFormValidate($field, $instance, $form, $form_state);
+  }
+}
+
+/**
+ * Implements hook_field_formatter_settings_summary().
+ */
+function tripal_field_formatter_settings_summary($field, $instance, $view_mode) {
+
+  $summary = '';
+  $field_type = $field['type'];
+  $is_loaded = tripal_load_include_field_type($field_type);
+  if ($is_loaded) {
+    $tfield = new $field_type(array('field' => $field));
+    $form = $tfield->formatterSettingsSummary($field, $instance, $view_mode);
+  }
+  return $summary;
+}
+
+/**
+ * Implements hook_field_formatter_settings_form().
+ */
+function tripal_formatter_settings_form($field, $instance,
+    $view_mode, $form, &$form_state) {
+
+  $form = array();
+  $field_type = $field['type'];
+  $is_loaded = tripal_load_include_field_type($field_type);
+  if ($is_loaded) {
+    $tfield = new $field_type(array('field' => $field));
+    $form = $tfield->formatterSettingsForm(field, $instance, $view_mode, $form, $form_state);
+  }
+  return $form;
+}
+
+
+/**
+ * Implements hook_field_widget_form().
+ */
+function tripal_field_widget_form(&$form, &$form_state, $field,
+    $instance, $langcode, $items, $delta, $element) {
+
+  $widget = $element;
+  $field_type = $field['type'];
+  $is_loaded = tripal_load_include_field_type($field_type);
+  if ($is_loaded) {
+    $tfield = new $field_type(array('field' => $field));
+    $tfield->widgetForm($widget, $form, $form_state, $field, $instance,
+      $langcode, $items, $delta, $element);
+  }
+  return $widget;
+
+
+}
+
+
+/**
+ * Implements hook_field_widget_form_alter().
+ */
+function tripal_field_widget_form_alter(&$element, &$form_state, $context) {
+
+  if (array_key_exists('#field_name', $element)) {
+    $field_name = $element['#field_name'];
+    $matches = array();
+
+    if (preg_match('/(.+?)__(.+?)$/', $field_name, $matches)) {
+      $tablename = $matches[1];
+      $colname = $matches[2];
+      $schema = chado_get_schema($tablename);
+      if (!$schema) {
+        return;
+      }
+
+      // The timelastmodified field exists in many Chado tables.  We want
+      // the form element to update to the most recent time rather than the time
+      // in the database.
+      if ($colname == 'timelastmodified' and $schema['fields'][$colname]['type'] == 'datetime') {
+        // We want the default value for the field to be the current time.
+        $element['#default_value']['value'] = format_date(time(), 'custom', "Y-m-d H:i:s", 'UTC');
+        $element['#date_items']['value'] = $element['#default_value']['value'];
+      }
+      // We want the date combo fieldset to be collaspible so we will
+      // add our own theme_wrapper to replace the one added by the date
+      // module.
+      if (array_key_exists($colname, $schema['fields']) and $schema['fields'][$colname]['type'] == 'datetime') {
+        $element['#theme_wrappers'] = array('tripal_chado_date_combo');
+      }
+    }
+  }
+}
+
+/**
+ * Implements hook_field_validate()
+ */
+function tripal_field_validate($entity_type, $entity, $field, $instance,
+    $langcode, $items, &$errors) {
+
+  $field_type = $field['type'];
+  $is_loaded = tripal_load_include_field_type($field_type);
+  if ($is_loaded) {
+    $tfield = new $field_type(array('field' => $field));
+    $bundle = isset($entity->bundle) ? $entity->bundle : NULL;
+    $form = $field_type::widgetFormValidate($entity_type, $entity, $field, $instance,
+        $langcode, $items, $errors);
+  }
+}
+
+/**
+ * Implements hook_field_submit()
+ *
+ * This is a TripalEntity specific hook.
+ */
+function tripal_field_submit($entity_type, $entity, $field, $instance,
+    $langcode, &$items, $form, &$form_state) {
+
+  $field_type = $field['type'];
+  $is_loaded = tripal_load_include_field_type($field_type);
+  if ($is_loaded) {
+    $tfield = new $field_type(array('field' => $field));
+    $form = $field_type::widgetFormSubmit($entity_type, $entity, $field, $instance,
+        $langcode, $items, $form, $form_state);
+  }
+}
+
+
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ *
+ * The field_ui_display_overview_form is used for formatting the display
+ * or layout of fields attached to an entity and shown on the entity view page.
+ *
+ * This function removes the cvterm class and property adder field as those are
+ * really not meant for users to show or manage.
+ */
+function tripal_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
+  // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
+  // on the add/edit form of an entity for adding new property fields.
+  $fields_names = element_children($form['fields']);
+  foreach ($fields_names as $field_name) {
+    $field_info = field_info_field($field_name);
+    if ($field_info['type'] == 'kvproperty_adder') {
+      unset($form['fields'][$field_name]);
+    }
+    if ($field_info['type'] == 'cvterm_class_adder') {
+      unset($form['fields'][$field_name]);
+    }
+  }
+}
+
+
+
+/**
+ * Implements hook_field_is_empty().
+ */
+function tripal_field_is_empty($item, $field) {
+
+  // If there is no value field then the field is empty.
+  if (!array_key_exists('value', $item)) {
+    return TRUE;
+  }
+
+  // Iterate through all of the fields and if at least one has a value
+  // the field is not empty.
+  foreach ($item as $form_field_name => $value) {
+    if (isset($value) and $value != NULL and $value != '') {
+      return FALSE;
+    }
+  }
+
+  // Otherwise, the field is empty.
+  return TRUE;
+}

+ 91 - 125
tripal_chado/includes/fields/chado_base__dbxref_id.inc → tripal_chado/includes/TripalFields/chado_base__dbxref_id.inc

@@ -1,132 +1,98 @@
 <?php
 
 class chado_base__dbxref_id extends TripalField {
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  static function fieldDefaults() {
-    return array(
-      'label' => t('Accession'),
-      'description' => t('This field specifies the unique stable accession (ID) for
-        this record. It requires that this site have a database entry.'),
-      'default_widget' => 'chado_base__dbxref_id_widget',
-      'default_formatter' => 'chado_base__dbxref_id_formatter',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::setCanAttach()
-   */
-  protected function setCanAttach() {
-
-    $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'];
-
-    // Check the schema for the data table if it does not have
-    // a 'dbxref_id' column then we don't want to attach this field.
-    $schema = chado_get_schema($table_name);
-    if (!$schema) {
-      $this->can_attach = FALSE;
-      return;
-    }
-    if (array_key_exists('dbxref_id', $schema['fields'])) {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
-
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
-
-    $this->field_name = $table_name . '__dbxref_id';
-  }
-
-  /**
-   * @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'];
-
-
-    return array(
-      'field_name' => $this->field_name,
-      'type' => 'chado_base__dbxref_id',
-      'cardinality' => 1,
-      'locked' => FALSE,
-      'storage' => array(
-        'type' => 'field_chado_storage',
-      ),
-      'settings' => array(
-        'chado_table' => $table_name,
-        'chado_column' => 'dbxref_id',
-        'semantic_web' => tripal_get_chado_semweb_term($table_name, 'dbxref_id'),
-      ),
-    );
-  }
-
-  /**
-   * @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'];
+  // The default lable for this field.
+  public static $default_label = 'Accession';
+
+  // The default description for this field.
+  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()
+  // or the instanceSettingsForm() functions then you need to be sure that
+  // any settings you want those functions to manage are listed in this
+  // array.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
 
-    return array(
-      'field_name' => $this->field_name,
-      'entity_type' => $this->entity_type,
-      'bundle' => $this->bundle->name,
-      'label' => 'Accession',
-      'description' => 'This field specifies the unique stable accession (ID) for
-        this record. It requires that this site have a database entry.',
-      'required' => FALSE,
-      'settings' => array(
-        'auto_attach' => TRUE,
-      ),
-      'widget' => array(
-        'type' => 'chado_base__dbxref_id_widget',
-        'settings' => array(
-          'display_label' => 1,
-        ),
-      ),
-      'display' => array(
-        'default' => array(
-          'label' => 'inline',
-          'type' => 'chado_base__dbxref_id_formatter',
-          'settings' => array(),
-        ),
-      ),
-    );
-  }
+  // 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::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'];
+
+
+//     return array(
+//       'field_name' => $this->field_name,
+//       'type' => 'chado_base__dbxref_id',
+//       'cardinality' => 1,
+//       'locked' => FALSE,
+//       'storage' => array(
+//         'type' => 'field_chado_storage',
+//       ),
+//       'settings' => array(
+//         'chado_table' => $table_name,
+//         'chado_column' => 'dbxref_id',
+//         'semantic_web' => tripal_get_chado_semweb_term($table_name, 'dbxref_id'),
+//       ),
+//     );
+//   }
+
+//   /**
+//    * @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' => 'Accession',
+//       'description' => 'This field specifies the unique stable accession (ID) for
+//         this record. It requires that this site have a database entry.',
+//       'required' => FALSE,
+//       'settings' => array(
+//         'auto_attach' => TRUE,
+//       ),
+//       'widget' => array(
+//         'type' => 'chado_base__dbxref_id_widget',
+//         'settings' => array(
+//           'display_label' => 1,
+//         ),
+//       ),
+//       'display' => array(
+//         'default' => array(
+//           'label' => 'inline',
+//           'type' => 'chado_base__dbxref_id_formatter',
+//           'settings' => array(),
+//         ),
+//       ),
+//     );
+//   }
   /**
    * @see TripalField::widgetInfo()
    */

+ 21 - 65
tripal_chado/includes/fields/chado_base__organism_id.inc → tripal_chado/includes/TripalFields/chado_base__organism_id.inc

@@ -1,72 +1,28 @@
 <?php
 
 class chado_base__organism_id extends TripalField {
+  // The default lable for this field.
+  public static $default_label = 'Organism';
+
+  // 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()
+  // or the instanceSettingsForm() functions then you need to be sure that
+  // any settings you want those functions to manage are listed in this
+  // array.
+  public static $default_settings = array(
+    'field_display_string' => '<i>[organism.genus] [organism.species]</i>',
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+  // 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::info()
-   */
-  public static function fieldDefaults() {
-    return array(
-      'label' => t('Organism'),
-      'description' => t('A field for specifying an organism.'),
-      'default_widget' => 'chado_base__organism_id_widget',
-      'default_formatter' => 'chado_base__organism_id_formatter',
-      'settings' => array(
-        'field_display_string' => '<i>[organism.genus] [organism.species]</i>',
-      ),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-
-    $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'];
-
-    $schema = chado_get_schema($table_name);
-    if (!$schema) {
-      $this->can_attach = FALSE;
-      return;
-    }
-
-    // If this is the organism table then do not attach as the organism_id
-    // field is the primary key and we don't want a field for that.
-    if ($table_name == 'organism') {
-      $this->can_attach = FALSE;
-      return;
-    }
-
-    // Check the schema for the data table if it has
-    // an 'organism_id' column then we want to attach this field.
-    if (array_key_exists('organism_id', $schema['fields'])) {
-      $this->can_attach = TRUE;
-      return;
-    }
-
-    $this->can_attach = FALSE;
-  }
-
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
-
-    $this->field_name = $table_name . '__organism_id';
-  }
 
   /**
    * @see TripalField::create_info()

+ 21 - 47
tripal_chado/includes/fields/chado_feature__md5checksum.inc → tripal_chado/includes/TripalFields/chado_feature__md5checksum.inc

@@ -1,53 +1,27 @@
 <?php
 
 class chado_feature__md5checksum  extends TripalField {
-
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  static function fieldDefaults() {
-    return array(
-      'label' => t('Sequence MD5 checksum'),
-      'description' => t('A field for generating MD5 checksum for a sequence.'),
-      'default_widget' => 'chado_feature__md5checksum_widget',
-      'default_formatter' => 'chado_feature__md5checksum_formatter',
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    $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'];
-
-    if ($table_name == 'feature') {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
-
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
-
-    $this->field_name = $table_name . '__md5checksum';
-  }
+  // The default lable for this field.
+  public static $default_label = 'Sequence MD5 checksum';
+
+  // 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()
+  // or the instanceSettingsForm() functions then you need to be sure that
+  // any settings you want those functions to manage are listed in this
+  // array.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+
+  // 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::create_info()

+ 21 - 35
tripal_chado/includes/fields/chado_feature__residues.inc → tripal_chado/includes/TripalFields/chado_feature__residues.inc

@@ -2,41 +2,27 @@
 
 class chado_feature__residues extends TripalField {
 
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  static function fieldDefaults() {
-    return array(
-      'label' => t('Sequences'),
-      'description' => t('A field for managing nucleotide and protein residues.'),
-      'default_widget' => 'chado_feature__residues_widget',
-      'default_formatter' => 'chado_feature__residues_formatter',
-      'settings' => array(),
-      'instance_settings' => array('text_processing' => 1, 'display_summary' => 0),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    $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'];
-
-    // If  this is not the feature table then we don't want to attach.
-    if ($table_name == 'feature') {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
+  // The default lable for this field.
+  public static $default_label = 'Sequences';
+
+  // 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()
+  // or the instanceSettingsForm() functions then you need to be sure that
+  // any settings you want those functions to manage are listed in this
+  // array.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+
+  // 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::setFieldName()

+ 20 - 47
tripal_chado/includes/fields/chado_feature__seqlen.inc → tripal_chado/includes/TripalFields/chado_feature__seqlen.inc

@@ -1,53 +1,26 @@
 <?php
 
 class chado_feature__seqlen extends TripalField {
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  static function fieldDefaults() {
-    return array(
-      'label' => t('Sequence length'),
-      'description' => t('A field for calculating the length of a sequence.'),
-      'default_widget' => 'chado_feature__seqlen_widget',
-      'default_formatter' => 'chado_feature__seqlen_formatter',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    $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'];
-
-    if ($table_name == 'feature') {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
-
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
-
-    $this->field_name = 'feature__seqlen';
-  }
+  // The default lable for this field.
+  public static $default_label = 'Sequence length';
+
+  // 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()
+  // or the instanceSettingsForm() functions then you need to be sure that
+  // any settings you want those functions to manage are listed in this
+  // array.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+  // 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::create_info()

+ 20 - 48
tripal_chado/includes/fields/chado_gene__transcripts.inc → tripal_chado/includes/TripalFields/chado_gene__transcripts.inc

@@ -1,55 +1,27 @@
 <?php
 
 class chado_gene__transcripts extends TripalField {
+  // The default lable for this field.
+  public static $default_label = 'Transcripts';
+
+  // The default description for this field.
+  public static $default_description = 'Transcripts of genes.';
+
+  // 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.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+  // 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::fieldDefaults()
-   */
-  public static function fieldDefaults() {
-    return array(
-      'label' => t('Transcripts'),
-      'description' => t('Transcripts of genes.'),
-      'default_widget' => 'chado_gene__transcripts_widget',
-      'default_formatter' => 'chado_gene__transcripts_formatter',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    $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'];
-
-    // If the linker table does not exists or this is not a gene then we don't want to add attach.
-    $rel_table = $table_name . '_relationship';
-    if (chado_table_exists($rel_table) and $this->bundle->label == 'gene') {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
-
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
-
-    $this->field_name = 'gene_transcripts';
-  }
 
   /**
    * @see TripalField::create_info()

+ 20 - 46
tripal_chado/includes/fields/chado_linker__contact.inc → tripal_chado/includes/TripalFields/chado_linker__contact.inc

@@ -2,55 +2,29 @@
 
 class chado_linker__contact extends TripalField {
 
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  public static function fieldDefaults() {
-    return array(
-      'label' => t('Contacts'),
-      'description' => t('Associates an indviddual or organization with
-          this record.'),
-      'default_widget' => 'chado_linker__contact_widget',
-      'default_formatter' => 'chado_linker__contact_formatter',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    $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'];;
+  // The default lable for this field.
+  public static $default_label = 'Contacts';
 
-    // If the linker table does not exists then we don't want to add attach.
-    $contact_table = $table_name . '_contact';
-    if (chado_table_exists($contact_table)) {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
+  // The default description for this field.
+  public static $default_description = 'Associates an indviddual or organization with
+          this record';
+
+  // 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.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+  // 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::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
 
-    $this->field_name = $table_name . '_contact';
-  }
 
   /**
    * @see TripalField::create_info()

+ 22 - 25
tripal_chado/includes/fields/chado_linker__cvterm.inc → tripal_chado/includes/TripalFields/chado_linker__cvterm.inc

@@ -1,32 +1,29 @@
 <?php
 
 class chado_linker__cvterm extends TripalField {
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  static function fieldDefaults() {
-    return array(
-      'label' => t('Annotations'),
-      'description' => t('This record can be annotated with terms
-            from other vocabularies.'),
-      'default_widget' => 'chado_linker__cvterm_widget',
-      'default_formatter' => 'chado_linker__cvterm_formatter',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
+  // The default lable for this field.
+  public static $default_label = 'Annotations';
+
+  // The default description for this field.
+  public static $default_description = 'This record can be annotated with terms
+            from other vocabularies.';
+
+  // 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.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+  // Set this to the name of the storage backend that by default will support
+  // this field.
+  public static $default_storage = 'field_chado_storage';
+
 
-    // This field is only attached by the chado_linker__cvterm_addr field.
-    $this->can_attach = FALSE;
-  }
   /**
    * @see TripalField::create_info()
    */

+ 18 - 48
tripal_chado/includes/fields/chado_linker__cvterm_adder.inc → tripal_chado/includes/TripalFields/chado_linker__cvterm_adder.inc

@@ -1,58 +1,28 @@
 <?php
 class chado_linker__cvterm_addr extends TripalField {
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  static function fieldDefaults() {
-    return array(
-      'label' => t('Add an Annotation Type'),
-      'description' => t('This record may have any number of types of
-        annotations. Use this field to first add the type.'),
-      'default_widget' => 'chado_linker__cvterm_adder_widget',
-      'default_formatter' => 'hidden',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-      'no_ui' => TRUE
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    $field_info = array();
 
-    $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'];
+  // The default lable for this field.
+  public static $default_label = 'Add an Annotation Type';
 
+  // The default description for this field.
+  public static $default_description = 'This record may have any number of types of
+        annotations. Use this field to first add the type.';
 
-    // If the linker table does not exists then we don't want to add attach.
-    $cvterm_table = $table_name . '_cvterm';
-    if (chado_table_exists($cvterm_table)) {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
+  // 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.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
 
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
+  // Set this to the name of the storage backend that by default will support
+  // this field.
+  public static $default_storage = 'field_chado_storage';
 
-    $this->field_name = $table_name . '_cvterm';
-  }
 
   /**
    * @see TripalField::create_info()

+ 22 - 49
tripal_chado/includes/fields/chado_linker__dbxref.inc → tripal_chado/includes/TripalFields/chado_linker__dbxref.inc

@@ -10,58 +10,31 @@
  *
  */
 class chado_linker__dbxref extends TripalField {
-  /**
-   * Implements hook_info() for fields.
-   *
-   * This is a hook provided by the tripal_chado module for offloading the
-   * hook_fieldInfo() hook for each field to specify.
-   */
-  static function fieldDefaults() {
-    return array(
-      'label' => t('Cross references'),
-      'description' => t('This record can be cross referenced with a record in
+
+  // The default lable for this field.
+  public static $default_label = 'Cross references';
+
+  // The default description for this field.
+  public static $default_description = 'This record can be cross referenced with a record in
           another online database. This field is intended for one or more
-          references.  At a minimum, the database and accession must be provided.'),
-      'default_widget' => 'chado_linker__dbxref_widget',
-      'default_formatter' => 'chado_linker__dbxref_formatter',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    $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'];
+          references.  At a minimum, the database and accession must be provided.';
+
+  // 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.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+  // Set this to the name of the storage backend that by default will support
+  // this field.
+  public static $default_storage = 'field_chado_storage';
 
-    // If the linker table does not exists then we don't want to add attach.
-    $dbxref_table = $table_name . '_dbxref';
-    if (chado_table_exists($dbxref_table)) {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
 
-    $this->field_name = $table_name . '_dbxref';
-  }
   /**
    * @see TripalField::create_info()
    */

+ 20 - 47
tripal_chado/includes/fields/chado_linker__expression.inc → tripal_chado/includes/TripalFields/chado_linker__expression.inc

@@ -1,56 +1,29 @@
 <?php
 
 class chado_linker__expression extends TripalField {
+  // The default lable for this field.
+  public static $default_label = 'Expression';
 
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  public static function fieldDefaults() {
-    return array(
-      'label' => t('Expression'),
-      'description' => t('Associates an expression with
-          this record.'),
-      'default_widget' => 'chado_linker__expression_widget',
-      'default_formatter' => 'chado_linker__expression_formatter',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    $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'];
+  // The default description for this field.
+  public static $default_description = 'Associates an expression with
+          this record.';
 
-    // If the linker table does not exists then we don't want to add attach.
-    $expression_table = $table_name . '_expression';
-    if (chado_table_exists($expression_table)) {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
+  // 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.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
 
-    $this->field_name = $table_name . '_expression';
-  }
-  /**
+  // 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::create_info()
    */
   function createInfo() {

+ 20 - 46
tripal_chado/includes/fields/chado_linker__featureloc.inc → tripal_chado/includes/TripalFields/chado_linker__featureloc.inc

@@ -2,53 +2,27 @@
 
 class chado_linker__featureloc extends TripalField {
 
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  public static function fieldDefaults() {
-    return array(
-      'label' => t('Aligned Locations'),
-      'description' => t('Locations on landmark sequences where the feature is aligned.'),
-      'default_widget' => 'chado_linker__featureloc_widget',
-      'default_formatter' => 'chado_linker__featureloc_formatter',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    $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'];
-
-    // If  this is not the feature table then we don't want to attach.
-    if ($table_name == 'feature') {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
-
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
+  // The default lable for this field.
+  public static $default_label = 'Aligned Locations';
+
+  // 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()
+  // or the instanceSettingsForm() functions then you need to be sure that
+  // any settings you want those functions to manage are listed in this
+  // array.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+  // Set this to the name of the storage backend that by default will support
+  // this field.
+  public static $default_storage = 'field_chado_storage';
 
-    $this->field_name = 'featureloc';
-  }
 
   /**
    * @see TripalField::create_info()

+ 21 - 73
tripal_chado/includes/fields/chado_linker__genotype.inc → tripal_chado/includes/TripalFields/chado_linker__genotype.inc

@@ -1,80 +1,28 @@
 <?php
 
 class chado_linker__genotype extends TripalField {
+  // The default lable for this field.
+  public static $default_label = 'Genotypes';
+
+  // The default description for this field.
+  public static $default_description = 'Associates an indviddual or organization with
+          this record.';
+
+  // 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.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+  // 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::fieldDefaults()
-   */
-  public static function fieldDefaults() {
-    return array(
-      'label' => t('Genotypes'),
-      'description' => t('Associates an indviddual or organization with
-          this record.'),
-      'default_widget' => 'chado_linker__genotype_widget',
-      'default_formatter' => 'chado_linker__genotype_formatter',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::widgetInfo()
-   */
-  public static function widgetInfo() {
-    return array(
-      'chado_linker__genotype_widget' => array(
-        'label' => t('Genotypes'),
-        'field types' => array('chado_linker__genotype'),
-      ),
-    );
-  }
-
-  /**
-   * @see TripalField::formatterInfo()
-   */
-  public static function formatterInfo() {
-    return array(
-      'chado_linker__genotype_formatter' => array(
-        'label' => t('Genotypes'),
-        'field types' => array('chado_linker__genotype'),
-        'settings' => array(
-        ),
-      ),
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    $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'];
-
-    // If the linker table does not exists then we don't want to add attach.
-    $genotype_table = $table_name . '_genotype';
-    if (chado_table_exists($genotype_table)) {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
-
-    $this->field_name = $table_name . '_genotype';
-  }
   /**
    * @see TripalField::create_info()
    */

+ 20 - 72
tripal_chado/includes/fields/chado_linker__phenotype.inc → tripal_chado/includes/TripalFields/chado_linker__phenotype.inc

@@ -2,79 +2,27 @@
 
 class chado_linker__phenotype extends TripalField {
 
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  public static function fieldDefaults() {
-    return array(
-      'label' => t('Phenotypes'),
-      'description' => t('Associates an indviddual or organization with
-          this record.'),
-      'default_widget' => 'chado_linker__phenotype_widget',
-      'default_formatter' => 'chado_linker__phenotype_formatter',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::widgetInfo()
-   */
-  public static function widgetInfo() {
-    return array(
-      'chado_linker__phenotype_widget' => array(
-        'label' => t('Phenotypes'),
-        'field types' => array('chado_linker__phenotype'),
-      ),
-    );
-  }
+  // The default lable for this field.
+  public static $default_label = 'Phenotypes';
+
+  // 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()
+  // or the instanceSettingsForm() functions then you need to be sure that
+  // any settings you want those functions to manage are listed in this
+  // array.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+  // 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::formatterInfo()
-   */
-  public static function formatterInfo() {
-    return array(
-      'chado_linker__phenotype_formatter' => array(
-        'label' => t('Phenotypes'),
-        'field types' => array('chado_linker__phenotype'),
-        'settings' => array(
-        ),
-      ),
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    $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'];
-
-    // If the linker table does not exists then we don't want to add attach.
-    $phenotype_table = $table_name . '_phenotype';
-    if (chado_table_exists($phenotype_table)) {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
-
-    $this->field_name = $table_name . '_phenotype';
-  }
   /**
    * @see TripalField::create_info()
    */

+ 20 - 69
tripal_chado/includes/fields/chado_linker__prop.inc → tripal_chado/includes/TripalFields/chado_linker__prop.inc

@@ -1,76 +1,27 @@
 <?php
 
 class chado_linker__prop extends TripalField {
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  static function fieldDefaults() {
-    return array(
-      'label' => t('Add a Property'),
-      'description' => t('Add details about this property.'),
-      'default_widget' => 'chado_linker__prop_widget',
-      'default_formatter' => 'chado_linker__prop_formatter',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    // This field is only attached by the chado_linker__prop_addr field.
-    $this->can_attach = FALSE;
-  }
-  /**
-   * @see TripalField::create_info()
-   */
-  function createInfo() {
-    if (!$this->can_attach) {
-      return;
-    }
-
-    // This field is only attached by the chado_linker__prop_addr field.
-
-  }
-  /**
-   * @see TripalField::createInstanceInfo()
-   */
-  function createInstanceInfo() {
-    if (!$this->can_attach) {
-      return;
-    }
-
-    // This field is only attached by the chado_linker__prop_addr field.
+  // The default lable for this field.
+  public static $default_label = 'Property';
+
+  // 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()
+  // or the instanceSettingsForm() functions then you need to be sure that
+  // any settings you want those functions to manage are listed in this
+  // array.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+  // 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::widgetInfo()
-   */
-  public static function widgetInfo() {
-    return array(
-      'chado_linker__prop_widget' => array(
-        'label' => t('Property'),
-        'field types' => array('chado_linker__prop'),
-      ),
-    );
-  }
-  /**
-   * @see TripalField::formatterInfo()
-   */
-  static function formatterInfo() {
-    return array(
-      'chado_linker__prop_formatter' => array(
-        'label' => t('Property'),
-        'field types' => array('chado_linker__prop'),
-        'settings' => array(
-        ),
-      ),
-    );
-  }
   /**
    * @see TripalField::formatterView()
    */

+ 21 - 48
tripal_chado/includes/fields/chado_linker__prop_adder.inc → tripal_chado/includes/TripalFields/chado_linker__prop_adder.inc

@@ -1,55 +1,28 @@
 <?php
 
 class chado_linker__prop_adder extends TripalField {
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  static function fieldDefaults() {
-    return array(
-      'label' => t('Add a Property Type'),
-      'description' => t('This record may have any number of properties. Use
-            this field to first add the type.'),
-      'default_widget' => 'chado_linker__prop_adder_widget',
-      'default_formatter' => 'hidden',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-      'no_ui' => TRUE
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    $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'];
-
-    // If the linker table does not exist then we don't want to add attach.
-    $prop_table = $table_name . 'prop';
-    if (chado_table_exists($prop_table)) {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
+  // The default lable for this field.
+  public static $default_label = 'Add a Property Type';
+
+  // The default description for this field.
+  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()
+  // or the instanceSettingsForm() functions then you need to be sure that
+  // any settings you want those functions to manage are listed in this
+  // array.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+  // Set this to the name of the storage backend that by default will support
+  // this field.
+  public static $default_storage = 'field_chado_storage';
 
-    $this->field_name = $table_name . 'prop';
-  }
   /**
    * @see TripalField::create_info()
    */

+ 21 - 46
tripal_chado/includes/fields/chado_linker__pub.inc → tripal_chado/includes/TripalFields/chado_linker__pub.inc

@@ -1,54 +1,29 @@
 <?php
 
 class chado_linker_pub extends TripalField {
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  static function fieldDefaults() {
-    return array(
-      'label' => t('Publications'),
-      'description' => t('Associates a publication (e.g. journal article,
-            conference proceedings, book chapter, etc.) with this record.'),
-      'default_widget' => 'chado_linker__pub_widget',
-      'default_formatter' => 'chado_linker__pub_formatter',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    $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'];
 
-    // If the linker table does not exists then we don't want to add attach.
-    $pub_table = $table_name . '_pub';
-    if (chado_table_exists($pub_table)) {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
+  // The default lable for this field.
+  public static $default_label = 'Publications';
+
+  // The default description for this field.
+  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()
+  // or the instanceSettingsForm() functions then you need to be sure that
+  // any settings you want those functions to manage are listed in this
+  // array.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+  // Set this to the name of the storage backend that by default will support
+  // this field.
+  public static $default_storage = 'field_chado_storage';
 
-    $this->field_name = $table_name . '_pub';
-  }
   /**
    * @see TripalField::create_info()
    */

+ 21 - 18
tripal_chado/includes/fields/chado_linker__relationship.inc → tripal_chado/includes/TripalFields/chado_linker__relationship.inc

@@ -1,24 +1,27 @@
 <?php
 
 class chado_linker__relationship extends TripalField {
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  static function fieldDefaults() {
-    return array(
-      'label' => t('Relationships'),
-      'description' => t('Relationships between records.'),
-      'default_widget' => 'chado_linker__relationship_widget',
-      'default_formatter' => 'chado_linker__relationship_formatter',
-      'settings' => array(
-      ),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
+  // The default lable for this field.
+  public static $default_label = 'Relationships';
+
+  // The default description for this field.
+  public static $default_description = 'Relationships between records.';
+
+  // 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.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+  // 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()

+ 20 - 46
tripal_chado/includes/fields/chado_linker__synonym.inc → tripal_chado/includes/TripalFields/chado_linker__synonym.inc

@@ -2,53 +2,27 @@
 
 class chado_linker__synonym extends TripalField {
 
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  static function fieldDefaults() {
-    return array(
-      'label' => t('Synonyms'),
-      'description' => t('Adds an alternative name (synonym or alias) to this record.'),
-      'default_widget' => 'chado_linker__synonym_widget',
-      'default_formatter' => 'chado_linker__synonym_formatter',
-      'settings' => array(),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach() {
-    $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'];
-
-    // If the linker table does not exists then we don't want to add attach.
-    $syn_table = $table_name . '_synonym';
-    if (chado_table_exists($syn_table)) {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
+  // The default lable for this field.
+  public static $default_label = 'Synonyms';
+
+  // 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()
+  // or the instanceSettingsForm() functions then you need to be sure that
+  // any settings you want those functions to manage are listed in this
+  // array.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+  // Set this to the name of the storage backend that by default will support
+  // this field.
+  public static $default_storage = 'field_chado_storage';
 
-    $this->field_name = $table_name . '_synonym';
-  }
   /**
    * @see TripalField::create_info()
    */

+ 20 - 50
tripal_chado/includes/fields/chado_organism__type_id.inc → tripal_chado/includes/TripalFields/chado_organism__type_id.inc

@@ -2,56 +2,26 @@
 
 class chado_organism__type_id extends TripalField {
 
-  /**
-   * @see TripalField::fieldDefaults()
-   */
-  public static function fieldDefaults() {
-    return array(
-      'label' => t('Infraspecific Type'),
-      'description' => t('A field for specifying an infraspecific type.'),
-      'default_widget' => 'chado_organism__type_id_widget',
-      'default_formatter' => 'chado_organism__type_id_formatter',
-      'settings' => array(
-      ),
-      'storage' => array(
-        'type' => 'field_chado_storage',
-        'module' => 'tripal_chado',
-        'active' => TRUE
-      ),
-    );
-  }
-  /**
-   * @see TripalField::can_attach()
-   */
-  protected function setCanAttach(){
-
-    $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'];
-
-    $schema = chado_get_schema($table_name);
-
-    // If this is the organism table and Chado v1.3 then attach.
-    if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
-      $this->can_attach = TRUE;
-      return;
-    }
-    $this->can_attach = FALSE;
-  }
-  /**
-   * @see TripalField::setFieldName()
-   */
-  protected function setFieldName() {
-    $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'];
-
-    $this->field_name = 'organism__type_id';
-  }
+  // The default lable for this field.
+  public static $default_label = 'Infraspecific Type';
+
+  // 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()
+  // or the instanceSettingsForm() functions then you need to be sure that
+  // any settings you want those functions to manage are listed in this
+  // array.
+  public static $default_settings = array(
+    'chado_table' => '',
+    'chado_column' => '',
+    'base_table' => '',
+    'semantic_web' => '',
+  );
+
+  // 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::create_info()
    */

File diff suppressed because it is too large
+ 574 - 461
tripal_chado/includes/tripal_chado.fields.inc


+ 7 - 7
tripal_chado/tripal_chado.module

@@ -580,31 +580,31 @@ function tripal_chado_theme($existing, $type, $theme, $path) {
     // Theme fields.
     'chado_base__dbxref_id_widget' => array(
       'render element' => 'element',
-      'file' => 'includes/fields/chado_base__dbxref_id.inc',
+      'file' => 'includes/TripalFields/chado_base__dbxref_id.inc',
     ),
     'chado_linker__dbxref_widget' => array(
       'render element' => 'element',
-      'file' => 'includes/fields/chado_linker__dbxref.inc',
+      'file' => 'includes/TripalFields/chado_linker__dbxref.inc',
     ),
     'chado_linker__cvterm_widget' => array(
       'render element' => 'element',
-      'file' => 'includes/fields/chado_linker__cvterm.inc',
+      'file' => 'includes/TripalFields/chado_linker__cvterm.inc',
     ),
     'chado_linker__synonym_widget' => array(
       'render element' => 'element',
-      'file' => 'includes/fields/chado_linker__synonym.inc',
+      'file' => 'includes/TripalFields/chado_linker__synonym.inc',
     ),
     'chado_linker__relationship_widget' => array(
       'render element' => 'element',
-      'file' => 'includes/fields/chado_linker__relationship.inc',
+      'file' => 'includes/TripalFields/chado_linker__relationship.inc',
     ),
     'chado_linker__pub_widget' => array(
       'render element' => 'element',
-      'file' => 'includes/fields/chado_linker__pub.inc',
+      'file' => 'includes/TripalFields/chado_linker__pub.inc',
     ),
     'chado_linker__prop_adder_widget' => array(
       'render element' => 'element',
-      'file' => 'includes/fields/chado_linker__prop_adder.inc',
+      'file' => 'includes/TripalFields/chado_linker__prop_adder.inc',
     ),
     'tripal_chado_date_combo' => array(
       'render element' => 'element',

Some files were not shown because too many files changed in this diff