Browse Source

Updating Views for Tripal entities.

Stephen Ficklin 8 years ago
parent
commit
71117751b7

+ 104 - 9
tripal/api/tripal.entities.api.inc

@@ -198,11 +198,14 @@ function tripal_refresh_bundle_fields($bundle_name) {
 
   // Allow modules now add fields to the bundle
   module_invoke_all('add_bundle_fields', 'TripalEntity', $bundle, $term);
+
+  // Allow modules to update existing fields
+  module_invoke_all('update_bundle_fields', 'TripalEntity', $bundle, $term);
 }
 
 
 /**
- * Adds a field to an Entity bundle.
+ * Adds a new field and attaches it to a bundle
  *
  * @param $field_name
  *   The name of the field.
@@ -231,19 +234,13 @@ function tripal_refresh_bundle_fields($bundle_name) {
  * @param $bundle_name
  *   The bundle name.
  *
+ * TODO: this function really shouldn't try to create an instance and
+ * attach to a bundle  at the same time.
  */
 function tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name) {
 
   $field = field_info_field($field_name);
 
-  // If the field is not present something is wrong and we should return.
-//   if (!$field) {
-//     tripal_report_error('tripal', TRIPAL_ERROR,
-//         "The field, '%name', cannot be found. Cannot add it to the bundle.",
-//         array('%name' => $field_name));
-//     return;
-//   }
-
   // If the field exists and is attached to this bundle then just return,
   // there is nothing left to do.
   if ($field and array_key_exists('bundles', $field) and
@@ -291,6 +288,104 @@ function tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $b
   field_create_instance($field_instance);
 }
 
+/**
+ * Updates an existing field and its attached instance to a bundle.
+ *
+ *
+ * @param $field_name
+ *   The name of the field.
+ * @param $field_info
+ *   An associative array containing the field information.  The following
+ *   key/value pairs are supported:
+ *     'field_type' : a valid field type.  May be any of the Drupal default
+ *       fields, one created by the tripal_chado module or another custom module.
+ *     'widget_type' : a valid widget type. May be any of the Drupal default
+ *       fields, one created by the tripal_chado module or another custom module.
+ *     'field_settings' : an array of settings that are appropriate for the
+ *       selected field type.
+ *     'widget_settings' : an array of settings that are appropriate for the
+ *       selected widget type.
+ *     'description' :  a default description for this field.
+ *     'label' : a label used as a header for this field.
+ *     'is_required' : indicates if the field is required in the edit form.
+ *     'cardinality' : indicates the number of values this field can support.
+ *       the default is 1 (meaning only one value). Use a value of
+ *       FIELD_CARDINALITY_UNLIMITED for unlimited number of values.
+ *     'default_value' : A default value for the field.
+ *     'format' : A string indicating the format for the field. Must be
+ *       specific to the field.
+ * @param $entity_type_name
+ *   The entity type name.
+ * @param $bundle_name
+ *   The bundle name.
+ *
+ * @return
+ *   FALSE if the field could not be updated
+ *
+ * TODO: this function really shouldn't try to create an instance and
+ * attach to a bundle  at the same time.
+ *
+ */
+function tripal_update_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name) {
+
+  $field = field_info_field($field_name);
+
+  // If the field doesn't exists or is not attached to this bundle then
+  // just return, there is nothing left to do.
+  if (!$field or !array_key_exists('bundles', $field) or
+      !array_key_exists($entity_type_name, $field['bundles']) or
+      !in_array($bundle_name, $field['bundles'][$entity_type_name])) {
+    return FALSE;
+  }
+
+  $field['field_name'] = $field_name;
+  if (array_key_exists('field_type', $field_info)) {
+    $field['cardinality'] = $field_info['cardinality'];
+  }
+  if (array_key_exists('locked', $field_info)) {
+    $field['locked'] = $field_info['locked'];
+  }
+  if (array_key_exists('storage', $field_info)) {
+    $field['storage']['type'] = $field_info['storage'];
+  }
+  if (array_key_exists('field_settings', $field_info)) {
+    $field['settings'] = $field_info['field_settings'];
+  }
+
+  field_update_field($field);
+
+  $field_instance['field_name'] = $field_name;
+  $field_instance['entity_type'] = $entity_type_name;
+  $field_instance['bundle'] = $bundle_name;
+  if (array_key_exists('label', $field_info)) {
+    $field['label'] = $field_info['label'];
+  }
+  if (array_key_exists('description', $field_info)) {
+    $field['description'] = $field_info['description'];
+  }
+  if (array_key_exists('widget', $field_info)) {
+    if (array_key_exists('widget_type', $field_info['widget'])) {
+      $field['widget']['type'] = $field_info['widget_type'];
+    }
+    if (array_key_exists('widget_settings', $field_info['widget'])) {
+      $field['widget']['settings'] = $field_info['widget_settings'];
+    }
+  }
+  if (array_key_exists('required', $field_info)) {
+    $field['required'] = $field_info['is_required'];
+  }
+  if (array_key_exists('settings', $field_info)) {
+    $field['settings'] = $field_info['field_settings'];
+  }
+  if (array_key_exists('default_value', $field_info)) {
+    $field['default_value'] = $field_info['default_value'];
+  }
+  if (array_key_exists('format', $field_info)) {
+    $field['format'] = $field_info['format'];
+  }
+  field_update_instance($field_instance);
+}
+
 /**
  * Allows a module to make changes to an entity object after creation.
  *

+ 26 - 0
tripal/includes/TripalEntityViewsController.inc

@@ -15,11 +15,37 @@ class TripalEntityViewsController extends EntityDefaultViewsController {
     $data['tripal_entity']['created']['field']['handler'] = 'views_handler_field_date';
     $data['tripal_entity']['created']['sort']['handler'] = 'views_handler_sort_date';
     $data['tripal_entity']['created']['filter']['handler'] = 'views_handler_filter_date';
+    $data['tripal_entity']['created']['help'] = t('The date that the content was created.');
     // Date Changed/Updated.
     $data['tripal_entity']['changed']['field']['handler'] = 'views_handler_field_date';
     $data['tripal_entity']['changed']['sort']['handler'] = 'views_handler_sort_date';
     $data['tripal_entity']['changed']['filter']['handler'] = 'views_handler_filter_date';
+    $data['tripal_entity']['changed']['help'] = t('The date that the content was last updated.');
 
+    $data['tripal_entity']['id']['title'] = 'Tripal Content ID';
+    $data['tripal_entity']['id']['help'] = 'The title for the content';
+
+    $data['tripal_entity']['id']['title'] = 'Tripal Content ID';
+    $data['tripal_entity']['id']['help'] = 'The unique numeric ID for the content';
+
+    $data['tripal_entity']['title']['help'] = 'The content\'s title.';
+    $data['tripal_entity']['uid']['help'] = 'The User\'s unique ID.';
+    $data['tripal_entity']['status']['help'] = 'The publish status.';
+
+    $data['tripal_entity']['uid']['relationship'] = array(
+      'base' => 'users',
+      'base field' => 'uid',
+      'handler' => 'views_handler_relationship',
+      'label' => t('Users'),
+      'title' => t('Users'),
+      'help' => t('Associates the user information with this record.')
+    );
+
+    // It is not intended that the following fields will every be used by the
+    // end-user within Views.
+    unset($data['tripal_entity']['bundle']);
+    unset($data['tripal_entity']['term_id']);
+    unset($data['tripal_entity']['type']);
     return $data;
   }
 

+ 20 - 2
tripal/includes/TripalField.inc

@@ -31,6 +31,17 @@ class TripalField {
     return array(
     );
   }
+
+
+  /**
+   * Provides an array that allows Tripal to attach a field to an entity.
+   *
+   * @todo: This function needs better documentation.
+   *
+   */
+  public function attach_info($entity_type, $bundle, $settings) {
+
+  }
   /**
    * Provides information about the widget for this field.
    *
@@ -242,10 +253,17 @@ class TripalField {
   }
 
   /**
-   * Provides an array that allows Tripal to attach a field to an entity.
+   * Describes this fields "data tables" to Views.
+   *
+   * This function is the equivalent of the hook_views_data() function of
+   * the Drupal Views API.  It provides the necessary details to allow
+   * Views to integrate the field.
    *
+   * @return
+   *   An associative array describing the data structure of the field.
    */
-  public function attach_info($entity_type, $bundle, $settings) {
+  public function views_data_alter(&$data, $field, $entity_info) {
 
   }
+
 }

+ 30 - 9
tripal/includes/TripalTermViewsController.inc

@@ -10,15 +10,26 @@ class TripalTermViewsController extends EntityDefaultViewsController {
   public function views_data() {
     $data = parent::views_data();
 
-    // Change handlers for Date Timestamps.
-    // Date Created.
-    $data['tripal_term']['created']['field']['handler'] = 'views_handler_field_date';
-    $data['tripal_term']['created']['sort']['handler'] = 'views_handler_sort_date';
-    $data['tripal_term']['created']['filter']['handler'] = 'views_handler_filter_date';
-    // Date Changed/Updated.
-    $data['tripal_term']['changed']['field']['handler'] = 'views_handler_field_date';
-    $data['tripal_term']['changed']['sort']['handler'] = 'views_handler_sort_date';
-    $data['tripal_term']['changed']['filter']['handler'] = 'views_handler_filter_date';
+    $data['tripal_term']['table']['group'] = 'Tripal Content Type';
+
+    $data['tripal_term']['accession']['title'] = 'Term ID';
+    $data['tripal_term']['accession']['help'] = t('The unique term ID (accession) of the vocabulary term to which a Tripal content type is asscoiated.');
+
+    $data['tripal_term']['name']['title'] = 'Content Type';
+    $data['tripal_term']['name']['help'] = t('The name of a Tripal content type.');
+    $data['tripal_term']['name']['filter']['handler'] = 'tripal_views_handler_filter_select_string';
+
+    $data['tripal_term']['vocab_id']['title'] = t('Vocabulary ID');
+    $data['tripal_term']['vocab_id']['help'] = t('The internal numeric ID for the vocabulary to which the content type term belongs.');
+    $data['tripal_term']['vocab_id']['relationship'] = array(
+      'base' => 'tripal_vocab',
+      'base field' => 'id',
+      'handler' => 'views_handler_relationship',
+      'label' => t('Tripal Content Vocabulary'),
+      'title' => t('Tripal Content Vocabulary'),
+      'help' => t('Associates the vocabulary ID of the Tripal content type with information about the vocabulary.')
+    );
+
 
     $data['tripal_term']['table']['join'] = array();
 
@@ -29,6 +40,16 @@ class TripalTermViewsController extends EntityDefaultViewsController {
       'field' => 'id',
     );
 
+    // It is not intended that the following fields will every be used by the
+    // end-user.
+    unset($data['tripal_term']['id']);
+    unset($data['tripal_term']['changed']);
+    unset($data['tripal_term']['created']);
+
+    // This should not be a base table. It's not useful to create a
+    // view of the tripal_term table.
+    unset($data['tripal_term']['table']['base']);
+
     return $data;
   }
 

+ 15 - 17
tripal/includes/TripalVocabViewsController.inc

@@ -10,23 +10,21 @@ class TripalVocabViewsController extends EntityDefaultViewsController {
   public function views_data() {
     $data = parent::views_data();
 
-    // Change handlers for Date Timestamps.
-    // Date Created.
-    $data['tripal_vocab']['created']['field']['handler'] = 'views_handler_field_date';
-    $data['tripal_vocab']['created']['sort']['handler'] = 'views_handler_sort_date';
-    $data['tripal_vocab']['created']['filter']['handler'] = 'views_handler_filter_date';
-    // Date Changed/Updated.
-    $data['tripal_vocab']['changed']['field']['handler'] = 'views_handler_field_date';
-    $data['tripal_vocab']['changed']['sort']['handler'] = 'views_handler_sort_date';
-    $data['tripal_vocab']['changed']['filter']['handler'] = 'views_handler_filter_date';
-
-    // Join the term to it's vocabulary so we know it's namespace.
-    $data['tripal_vocab']['table']['join'] = array();
-    $data['tripal_vocab']['table']['join']['tripal_term'] = array(
-      'handler' => 'views_join',
-      'left_field' => 'vocab_id',
-      'field' => 'id',
-    );
+    $data['tripal_vocab']['table']['group'] = 'Tripal Content Vocabulary';
+
+    $data['tripal_vocab']['namespace']['title'] = 'Namespace';
+    $data['tripal_vocab']['namespace']['help'] = t('The namespace of the vocabulary.');
+
+
+    // It is not intended that the following fields will every be used by the
+    // end-user.
+    unset($data['tripal_vocab']['id']);
+    unset($data['tripal_vocab']['changed']);
+    unset($data['tripal_vocab']['created']);
+
+    // This should not be a base table. It's not useful to create a
+    // view of the tripal_term table.
+    unset($data['tripal_vocab']['table']['base']);
 
     return $data;
   }

+ 0 - 246
tripal/includes/tripal.views_default.inc

@@ -1,246 +0,0 @@
-<?php
-
-/**
- * Implements hook_views_default_views().
- * Define default views related primarily to tripal entities.
- */
-function tripal_views_default_views() {
-  $views = array();
-
-// Vocabulary Search.
-$view = new view();
-$view->name = 'tripal_vocabularies';
-$view->description = '';
-$view->tag = 'default';
-$view->base_table = 'tripal_vocab';
-$view->human_name = 'Search Vocabularies';
-$view->core = 7;
-$view->api_version = '3.0';
-$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
-
-/* Display: Master */
-$handler = $view->new_display('default', 'Master', 'default');
-$handler->display->display_options['title'] = 'Search Vocabularies';
-$handler->display->display_options['use_more_always'] = FALSE;
-$handler->display->display_options['access']['type'] = 'none';
-$handler->display->display_options['cache']['type'] = 'none';
-$handler->display->display_options['query']['type'] = 'views_query';
-$handler->display->display_options['exposed_form']['type'] = 'input_required';
-$handler->display->display_options['exposed_form']['options']['submit_button'] = 'Search';
-$handler->display->display_options['exposed_form']['options']['text_input_required'] = 'Use the namespace to search for specific vocabularies or leave it blank to see all vocabularies currently in use on your site.';
-$handler->display->display_options['exposed_form']['options']['text_input_required_format'] = 'filtered_html';
-$handler->display->display_options['pager']['type'] = 'full';
-$handler->display->display_options['pager']['options']['items_per_page'] = '50';
-$handler->display->display_options['pager']['options']['offset'] = '0';
-$handler->display->display_options['pager']['options']['id'] = '0';
-$handler->display->display_options['pager']['options']['quantity'] = '9';
-$handler->display->display_options['style_plugin'] = 'table';
-/* Field: Controlled Vocabulary: Namespace */
-$handler->display->display_options['fields']['namespace']['id'] = 'namespace';
-$handler->display->display_options['fields']['namespace']['table'] = 'tripal_vocab';
-$handler->display->display_options['fields']['namespace']['field'] = 'namespace';
-/* Field: Controlled Vocabulary: Created */
-$handler->display->display_options['fields']['created']['id'] = 'created';
-$handler->display->display_options['fields']['created']['table'] = 'tripal_vocab';
-$handler->display->display_options['fields']['created']['field'] = 'created';
-/* Field: Controlled Vocabulary: Changed */
-$handler->display->display_options['fields']['changed']['id'] = 'changed';
-$handler->display->display_options['fields']['changed']['table'] = 'tripal_vocab';
-$handler->display->display_options['fields']['changed']['field'] = 'changed';
-/* Filter criterion: Controlled Vocabulary: Namespace */
-$handler->display->display_options['filters']['namespace']['id'] = 'namespace';
-$handler->display->display_options['filters']['namespace']['table'] = 'tripal_vocab';
-$handler->display->display_options['filters']['namespace']['field'] = 'namespace';
-$handler->display->display_options['filters']['namespace']['operator'] = 'contains';
-$handler->display->display_options['filters']['namespace']['exposed'] = TRUE;
-$handler->display->display_options['filters']['namespace']['expose']['operator_id'] = 'namespace_op';
-$handler->display->display_options['filters']['namespace']['expose']['label'] = 'Namespace';
-$handler->display->display_options['filters']['namespace']['expose']['description'] = 'The vocabulary namespace (partial names accepted).';
-$handler->display->display_options['filters']['namespace']['expose']['operator'] = 'namespace_op';
-$handler->display->display_options['filters']['namespace']['expose']['identifier'] = 'namespace';
-$handler->display->display_options['filters']['namespace']['expose']['remember_roles'] = array(
-  2 => '2',
-  1 => 0,
-  3 => 0,
-);
-
-/* Display: Page */
-$handler = $view->new_display('page', 'Page', 'page');
-$handler->display->display_options['path'] = 'admin/tripal/terms/vocabulary-search';
-$handler->display->display_options['menu']['type'] = 'normal';
-$handler->display->display_options['menu']['title'] = 'Search Vocabularies';
-$handler->display->display_options['menu']['description'] = 'Search the vocabularies currently in use.';
-$handler->display->display_options['menu']['weight'] = '0';
-$handler->display->display_options['menu']['name'] = 'management';
-$handler->display->display_options['menu']['context'] = 0;
-$handler->display->display_options['menu']['context_only_inline'] = 0;
-
-$views[$view->name] = $view;
-
-// Term Search.
-$view = new view();
-$view->name = 'tripal_terms';
-$view->description = '';
-$view->tag = 'default';
-$view->base_table = 'tripal_term';
-$view->human_name = 'Search Terms';
-$view->core = 7;
-$view->api_version = '3.0';
-$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
-
-/* Display: Master */
-$handler = $view->new_display('default', 'Master', 'default');
-$handler->display->display_options['title'] = 'Search Terms';
-$handler->display->display_options['use_more_always'] = FALSE;
-$handler->display->display_options['access']['type'] = 'none';
-$handler->display->display_options['cache']['type'] = 'none';
-$handler->display->display_options['query']['type'] = 'views_query';
-$handler->display->display_options['exposed_form']['type'] = 'input_required';
-$handler->display->display_options['exposed_form']['options']['submit_button'] = 'Search';
-$handler->display->display_options['exposed_form']['options']['text_input_required'] = 'Use the filters to search for the term you are interested in or leave them blank to see all terms defining Tripal Content Types.';
-$handler->display->display_options['exposed_form']['options']['text_input_required_format'] = 'filtered_html';
-$handler->display->display_options['pager']['type'] = 'full';
-$handler->display->display_options['pager']['options']['items_per_page'] = '50';
-$handler->display->display_options['style_plugin'] = 'table';
-$handler->display->display_options['style_options']['columns'] = array(
-  'namespace' => 'namespace',
-  'name' => 'name',
-  'accession' => 'accession',
-  'created' => 'created',
-  'changed' => 'changed',
-);
-$handler->display->display_options['style_options']['default'] = '-1';
-$handler->display->display_options['style_options']['info'] = array(
-  'namespace' => array(
-    'sortable' => 1,
-    'default_sort_order' => 'asc',
-    'align' => '',
-    'separator' => '',
-    'empty_column' => 0,
-  ),
-  'name' => array(
-    'sortable' => 1,
-    'default_sort_order' => 'asc',
-    'align' => '',
-    'separator' => '',
-    'empty_column' => 0,
-  ),
-  'accession' => array(
-    'sortable' => 1,
-    'default_sort_order' => 'asc',
-    'align' => '',
-    'separator' => '',
-    'empty_column' => 0,
-  ),
-  'created' => array(
-    'sortable' => 1,
-    'default_sort_order' => 'asc',
-    'align' => '',
-    'separator' => '',
-    'empty_column' => 0,
-  ),
-  'changed' => array(
-    'sortable' => 1,
-    'default_sort_order' => 'asc',
-    'align' => '',
-    'separator' => '',
-    'empty_column' => 0,
-  ),
-);
-/* Field: Controlled Vocabulary: Namespace */
-$handler->display->display_options['fields']['namespace']['id'] = 'namespace';
-$handler->display->display_options['fields']['namespace']['table'] = 'tripal_vocab';
-$handler->display->display_options['fields']['namespace']['field'] = 'namespace';
-/* Field: Controlled Vocabulary Term: Name */
-$handler->display->display_options['fields']['name']['id'] = 'name';
-$handler->display->display_options['fields']['name']['table'] = 'tripal_term';
-$handler->display->display_options['fields']['name']['field'] = 'name';
-/* Field: Controlled Vocabulary Term: Accession */
-$handler->display->display_options['fields']['accession']['id'] = 'accession';
-$handler->display->display_options['fields']['accession']['table'] = 'tripal_term';
-$handler->display->display_options['fields']['accession']['field'] = 'accession';
-/* Field: Controlled Vocabulary Term: Created */
-$handler->display->display_options['fields']['created']['id'] = 'created';
-$handler->display->display_options['fields']['created']['table'] = 'tripal_term';
-$handler->display->display_options['fields']['created']['field'] = 'created';
-$handler->display->display_options['fields']['created']['date_format'] = 'short';
-$handler->display->display_options['fields']['created']['second_date_format'] = 'long';
-/* Field: Controlled Vocabulary Term: Changed */
-$handler->display->display_options['fields']['changed']['id'] = 'changed';
-$handler->display->display_options['fields']['changed']['table'] = 'tripal_term';
-$handler->display->display_options['fields']['changed']['field'] = 'changed';
-$handler->display->display_options['fields']['changed']['date_format'] = 'short';
-$handler->display->display_options['fields']['changed']['second_date_format'] = 'long';
-/* Sort criterion: Controlled Vocabulary: Namespace */
-$handler->display->display_options['sorts']['namespace']['id'] = 'namespace';
-$handler->display->display_options['sorts']['namespace']['table'] = 'tripal_vocab';
-$handler->display->display_options['sorts']['namespace']['field'] = 'namespace';
-/* Sort criterion: Controlled Vocabulary Term: Name */
-$handler->display->display_options['sorts']['name']['id'] = 'name';
-$handler->display->display_options['sorts']['name']['table'] = 'tripal_term';
-$handler->display->display_options['sorts']['name']['field'] = 'name';
-/* Filter criterion: Controlled Vocabulary: Namespace */
-$handler->display->display_options['filters']['namespace']['id'] = 'namespace';
-$handler->display->display_options['filters']['namespace']['table'] = 'tripal_vocab';
-$handler->display->display_options['filters']['namespace']['field'] = 'namespace';
-$handler->display->display_options['filters']['namespace']['operator'] = 'contains';
-$handler->display->display_options['filters']['namespace']['exposed'] = TRUE;
-$handler->display->display_options['filters']['namespace']['expose']['operator_id'] = 'namespace_op';
-$handler->display->display_options['filters']['namespace']['expose']['label'] = 'Vocabulary Namespace';
-$handler->display->display_options['filters']['namespace']['expose']['description'] = 'The vocabulary namespace (partial names accepted).';
-$handler->display->display_options['filters']['namespace']['expose']['operator'] = 'namespace_op';
-$handler->display->display_options['filters']['namespace']['expose']['identifier'] = 'namespace';
-$handler->display->display_options['filters']['namespace']['expose']['remember_roles'] = array(
-  2 => '2',
-  1 => 0,
-  3 => 0,
-);
-/* Filter criterion: Controlled Vocabulary Term: Accession */
-$handler->display->display_options['filters']['accession']['id'] = 'accession';
-$handler->display->display_options['filters']['accession']['table'] = 'tripal_term';
-$handler->display->display_options['filters']['accession']['field'] = 'accession';
-$handler->display->display_options['filters']['accession']['operator'] = 'contains';
-$handler->display->display_options['filters']['accession']['exposed'] = TRUE;
-$handler->display->display_options['filters']['accession']['expose']['operator_id'] = 'accession_op';
-$handler->display->display_options['filters']['accession']['expose']['label'] = 'Accession';
-$handler->display->display_options['filters']['accession']['expose']['description'] = 'The accession of the term (partial accessions accepted).';
-$handler->display->display_options['filters']['accession']['expose']['operator'] = 'accession_op';
-$handler->display->display_options['filters']['accession']['expose']['identifier'] = 'accession';
-$handler->display->display_options['filters']['accession']['expose']['remember_roles'] = array(
-  2 => '2',
-  1 => 0,
-  3 => 0,
-);
-/* Filter criterion: Controlled Vocabulary Term: Name */
-$handler->display->display_options['filters']['name']['id'] = 'name';
-$handler->display->display_options['filters']['name']['table'] = 'tripal_term';
-$handler->display->display_options['filters']['name']['field'] = 'name';
-$handler->display->display_options['filters']['name']['operator'] = 'contains';
-$handler->display->display_options['filters']['name']['exposed'] = TRUE;
-$handler->display->display_options['filters']['name']['expose']['operator_id'] = 'name_op';
-$handler->display->display_options['filters']['name']['expose']['label'] = 'Name';
-$handler->display->display_options['filters']['name']['expose']['description'] = 'The name of the term (partial names accepted).';
-$handler->display->display_options['filters']['name']['expose']['operator'] = 'name_op';
-$handler->display->display_options['filters']['name']['expose']['identifier'] = 'name';
-$handler->display->display_options['filters']['name']['expose']['remember_roles'] = array(
-  2 => '2',
-  1 => 0,
-  3 => 0,
-);
-
-/* Display: Page */
-$handler = $view->new_display('page', 'Page', 'page');
-$handler->display->display_options['path'] = 'admin/tripal/terms/term-search';
-$handler->display->display_options['menu']['type'] = 'normal';
-$handler->display->display_options['menu']['title'] = 'Search Terms';
-$handler->display->display_options['menu']['description'] = 'Search the terms currently defining Tripal Content Types.';
-$handler->display->display_options['menu']['weight'] = '0';
-$handler->display->display_options['menu']['name'] = 'management';
-$handler->display->display_options['menu']['context'] = 0;
-$handler->display->display_options['menu']['context_only_inline'] = 0;
-
-$views[$view->name] = $view;
-
-  return $views;
-}
-

+ 2 - 0
tripal/tripal.info

@@ -9,6 +9,8 @@ configure = admin/tripal
 stylesheets[all][] = theme/css/tripal.css
 scripts[]          = theme/js/tripal.js
 
+files[] = views_handlers/tripal_views_handler_filter_select_string.inc
+
 dependencies[] = views
 dependencies[] = path
 dependencies[] = search

+ 48 - 0
tripal/tripal.views.inc

@@ -281,3 +281,51 @@ function tripal_views_data_jobs($data) {
   return $data;
 }
 
+
+/**
+ * Implements hook_views_handlers().
+ *
+ * Purpose: Register all custom handlers with views
+ *   where a handler describes either "the type of field",
+ *   "how a field should be filtered", "how a field should be sorted"
+ *
+ * @return
+ *   An array of handler definitions
+ *
+ * @ingroup tripal_views
+ */
+function tripal_views_views_handlers() {
+
+  return array(
+    'info' => array(
+      'path' => drupal_get_path('module', 'tripal') . '/views_handlers',
+    ),
+    'handlers' => array(
+//       // Custom area handler
+//       'tripal_views_handler_area_action_links' => array(
+//         'parent' => 'views_handler_area',
+//       ),
+
+      // Custom Tripal Filter Handlers
+//       'tripal_views_handler_filter_no_results' => array(
+//         'parent' => 'views_handler_filter'
+//       ),
+//       'tripal_views_handler_filter_select_cvterm' => array(
+//         'parent' => 'tripal_views_handler_filter_select_string',
+//       ),
+//       'tripal_views_handler_filter_select_id' => array(
+//         'parent' => 'tripal_views_handler_filter_select_string',
+//       ),
+      'tripal_views_handler_filter_select_string' => array(
+        'parent' => 'views_handler_filter_string',
+      ),
+//       'tripal_views_handler_filter_textarea' => array(
+//         'parent' => 'views_handler_filter',
+//       ),
+//       'tripal_views_handler_filter_file_upload' => array(
+//         'parent' => 'views_handler_filter',
+//       ),
+
+    ),
+  );
+}

+ 362 - 0
tripal/views_handlers/tripal_views_handler_filter_select_string.inc

@@ -0,0 +1,362 @@
+<?php
+/**
+ * @file
+* Contains tripal_views_handler_filter_select_string Filter Handler
+*/
+
+/**
+ * This Handler provides a generic select list for any chado field that is a string
+*  The select list includes all distinct values for that field.
+*
+* @ingroup tripal_views
+*/
+class tripal_views_handler_filter_select_string extends views_handler_filter_string {
+
+  /**
+   * {@inheritdoc}
+   */
+  function init(&$view, &$options) {
+    parent::init($view, $options);
+
+    // Backwards compatibility
+    if (isset($this->options['expose']['values_form_type'])) {
+      $this->options['values_form_type'] = $this->options['expose']['values_form_type'];
+      unset($this->options['expose']['values_form_type']);
+    }
+    if (isset($this->options['expose']['select_multiple'])) {
+      $this->options['select_multiple'] = $this->options['expose']['select_multiple'];
+      unset($this->options['expose']['select_multiple']);
+    }
+    if (isset($this->options['expose']['select_optional'])) {
+      $this->options['select_optional'] = $this->options['expose']['select_optional'];
+      unset($this->options['expose']['select_optional']);
+    }
+    if (isset($this->options['expose']['max_length'])) {
+      $this->options['max_length'] = $this->options['expose']['max_length'];
+      unset($this->options['expose']['max_length']);
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  function has_extra_options() {
+    return TRUE;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  function option_definition() {
+    $options = parent::option_definition();
+
+    $options['values_form_type'] = array(
+      'default' => 'textfield',
+      'export' => TRUE
+    );
+    $options['select_multiple'] = array(
+      'default' => FALSE,
+      'bool' => TRUE,
+      'export' => TRUE
+    );
+    $options['select_optional'] = array(
+      'default' => FALSE,
+      'bool' => TRUE,
+      'export' => TRUE
+    );
+    $options['show_all'] = array(
+      'default' => FALSE,
+      'bool' => TRUE,
+      'export' => TRUE
+    );
+    $options['max_length'] = array(
+      'default' => 40,
+      'export' => TRUE
+    );
+
+    return $options;
+  }
+
+  /**
+   * Provide the options used in the select list.
+   * Override this function in extended handlers to easily change option list.
+   *
+   * @return
+   *   An array of options where the key is the value of this field in the database
+   */
+  function get_select_options() {
+
+    $return = $this->get_select_option_where();
+    $where_clauses = $return['where_clauses'];
+    $arguements = $return['arguements'];
+    $where = '';
+    if (!empty($where_clauses)) {
+      $where = ' WHERE ' . implode(' AND ', $where_clauses);
+    }
+
+    // get the values from the table
+    $sql = 'SELECT ' . $this->real_field . ' FROM {' . $this->table . '} ' . $where . ' ORDER BY ' . $this->field . ' ASC';
+    $results = db_query($sql, $arguements);
+
+    // Build the select box options
+    $max_length = (isset($this->options['max_length'])) ? $this->options['max_length'] : 40;
+    if (!$max_length) {
+      $max_length = 40;
+    }
+    $options = array();
+    if ($this->options['select_optional']) {
+      $options['All'] = '--Any--';
+    }
+    foreach ($results as $r) {
+      if (drupal_strlen($r->{$this->field}) > $max_length) {
+        $options[$r->{$this->field}] = drupal_substr($r->{$this->field}, 0, $max_length) . '...';
+      }
+      else {
+        $options[$r->{$this->field}] = $r->{$this->field};
+      }
+    }
+
+    return $options;
+  }
+
+  /**
+   * For the SQL generating the options, determine the WHERE clauses
+   *
+   * @return
+   *   An array of full qualified where clauses (ie: table.myfield = 'fred')
+   */
+  function get_select_option_where($table = NULL, $generic_placeholder = TRUE) {
+    $where = array();
+    $values = array();
+
+    $table = (is_null($table)) ? $this->table : $table;
+
+    // build a where clause that will filter the list in the drop box
+    // using fields that are not exposed and that are for the table
+    // from whcih the values in the drop box will be slected and
+    // we only want to use non-exposed fields because these are not
+    // available to the user to edit--they're fixed.
+    $where = array();
+    $filters = (is_array($this->view->filter)) ? $this->view->filter : array();
+    $placeholder_prefix = 'arg';
+    $i = 0;
+    foreach ($filters as $filter_name => $details) {
+      // we only want to inclue non-exposed filters
+      if ($details->options['exposed'] == FALSE) {
+        $i++;
+
+        $value = $details->value;
+        if (is_array($details->value) AND isset($details->value['value'])) {
+          $value = $details->value['value'];
+        }
+
+        // Generate the current placeholder.
+        if ($generic_placeholder) {
+          $placeholder = ':'.$placeholder_prefix.$i;
+        }
+        else {
+          $placeholder = $details->real_field;
+        }
+
+        // we only want to filter on the table we're getting the list from
+        if (strcmp($details->table, $table)==0 AND !empty($value)) {
+
+          // If the value is an array then use IN instead of the choosen operator.
+          if (is_array($value)) {
+            $where[] = "$details->field IN ($placeholder)";
+            $values[$placeholder] = $value;
+          }
+          // Otherwise, just use the operator choosen by the admin.
+          else {
+            $where[] = "$details->field $details->operator $placeholder";
+            $values[$placeholder] = $value;
+          }
+        }
+      }
+    }
+
+    return array(
+      'where_clauses' => $where,
+      'arguements' => $values
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  function extra_options_form(&$form, &$form_state) {
+    parent::extra_options_form($form, $form_state);
+
+    $form['values_form_type'] = array(
+      '#type' => 'radios',
+      '#title' => t('Filter Type'),
+      '#options' => array(
+        'textfield' => 'Text Field',
+        'select' => 'Drop-Down Box',
+      ),
+      '#default_value' => $this->options['values_form_type'],
+    );
+
+    $form['show_all'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Show All'),
+      '#description' => t('When selected all terms from the controlled vocaulbary used by the table will be shown where the default is to only show those that are used.'),
+      '#default_value' => $this->options['show_all'],
+    );
+
+    $form['select_multiple'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Select Multiple'),
+      '#description' => t('Allows more then one option to be selected.'),
+      '#default_value' => $this->options['select_multiple'],
+    );
+
+    $form['select_optional'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Optional'),
+      '#description' => t('Adds --Any-- to the available options.'),
+      '#default_value' => $this->options['select_optional'],
+    );
+
+    $form['max_length'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Max Width'),
+      '#description' => t('Specify the maximum width of the select box'),
+      '#default_value' => $this->options['max_length'],
+    );
+
+    $form['note'] = array(
+      '#type' => 'markup',
+      '#value' => t('<strong><font color="red">Note:</font></strong> If another filter exists for the same table then '.
+          'the values shown in the drop box will only include those from rows that are not filtered.'),
+
+    );
+
+    return $form;
+
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  function extra_options_submit($form, &$form_state) {
+    $this->options['values_form_type'] = $form_state['values']['options']['values_form_type'];
+    $this->options['select_multiple'] = $form_state['values']['options']['select_multiple'];
+    $this->options['select_optional'] = $form_state['values']['options']['select_optional'];
+    $this->options['max_length'] = $form_state['values']['options']['max_length'];
+    $this->options['show_all'] = $form_state['values']['options']['show_all'];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  function extra_options_options() {
+    $this->options['values_form_type'] = 'textfield';
+    $this->options['select_multiple'] = FALSE;
+    $this->options['select_optional'] = FALSE;
+    $this->options['max_length'] = 40;
+    $this->options['show_all'] = FALSE;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  function value_form(&$form, &$form_state) {
+    parent::value_form($form, $form_state);
+
+    $this->options['values_form_type'] = (isset($this->options['values_form_type'])) ? $this->options['values_form_type'] : 'textfield';
+
+    if (preg_match('/select/', $this->options['values_form_type'])) {
+
+      //Select List
+      $form['value'] = array(
+        '#type' => 'select',
+        '#title' => t('%label', array('%label' => $this->options['expose']['label'])),
+        '#options' => $this->get_select_options(),
+        '#default_value' => $this->value,
+      );
+
+      if ($this->options['select_multiple']) {
+        $form['value']['#multiple'] = TRUE;
+      }
+    }
+    else {
+
+      $form['value'] = array(
+        '#type' => 'textfield',
+        '#title' => t('%label', array('%label' => $this->options['expose']['label'])),
+        '#default_value' => $this->value,
+      );
+
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  function exposed_form(&$form, &$form_state) {
+    parent::exposed_form($form, $form_state);
+
+    if (isset($this->options['select_multiple'])) {
+      if ($this->options['select_multiple']) {
+
+        if (isset($this->options['expose']['identifier'])) {
+          $id = $this->options['expose']['identifier'];
+        }
+        else {
+          $id = $this->options['id'];
+        }
+        $form[$id]['#multiple'] = TRUE;
+      }
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  function query() {
+
+    // make optional
+    // if it is not set or empty then don't restrict the query
+    if (!$this->value) {
+      return;
+    }
+
+    $this->ensure_my_table();
+    $field = $this->table_alias . "." . $this->real_field;
+    $table = $this->query->get_table_info($this->table);
+
+    $this->options['values_form_type'] = (isset($this->options['values_form_type'])) ? $this->options['values_form_type'] : 'textfield';
+    if (preg_match('/select/', $this->options['values_form_type'])) {
+      if (is_array($this->value)) {
+        if (isset($this->value['All'])) {
+          unset($this->value['All']);
+        }
+
+        if ($this->operator == '!=') {
+          $this->operator = 'NOT IN';
+        }
+        else {
+          $this->operator = 'IN';
+        }
+      }
+      else {
+        // don't allow operators other than = and !=
+        if ($this->operator != '!=') {
+          $this->operator = '=';
+        }
+      }
+
+      if ($this->value) {
+        $this->query->add_where($this->options['group'], $field, $this->value, $this->operator);
+      }
+    }
+    else {
+      $info = $this->operators();
+      if (!empty($info[$this->operator]['method'])) {
+        $this->{$info[$this->operator]['method']}($field);
+      }
+    }
+
+  }
+}

+ 17 - 17
tripal_chado/includes/chado_views_handler_filter.inc

@@ -15,11 +15,11 @@ class chado_views_handler_filter_boolean extends views_handler_filter_boolean_op
   function value_form(&$form, &$form_state) {
     parent::value_form($form, $form_state);
 
-    // change the keys of the options so that this filter can be optional.
+    // Change the keys of the options so that this filter can be optional.
     $form['value']['#options']['f'] = $form['value']['#options'][0];
     $form['value']['#options']['t'] = $form['value']['#options'][1];
     unset($form['value']['#options'][0], $form['value']['#options'][1]);
- 
+
   }
 
   /**
@@ -50,7 +50,7 @@ class chado_views_handler_filter_date extends views_handler_filter_date {
 
     // Adds joins to chado_entity and the chado table this field is from.
     $alias = _chado_views_add_table_joins($this);
-   
+
     // Then allow the parent handler to add the where.
     $field = $alias .'.'. $this->definition['chado_field'];
     $info = $this->operators();
@@ -93,7 +93,7 @@ class chado_views_handler_filter_date extends views_handler_filter_date {
  * Adds support for chado foreign key filters.
  */
 class chado_views_handler_filter_fk extends views_handler_filter {
-  
+
   /**
    * {@inheritdoc}
    */
@@ -106,7 +106,7 @@ class chado_views_handler_filter_fk extends views_handler_filter {
     if (is_array($this->value[0]) AND sizeof($this->value) == 1) {
       $this->value = $this->value[0];
     }
-    
+
     // Now add the restriction to the chado table as specified by user input.
     if (sizeof($this->value) == 1) {
       $value = current($this->value);
@@ -173,16 +173,16 @@ class chado_views_handler_filter_fk extends views_handler_filter {
       }
     }
   }
-  
+
   function get_select_options() {
 
     if (isset($this->options['display_column'])) {
       $name_field = $this->options['display_column'];
-    } 
+    }
     else {
       $name_field = 'name';
     }
-    
+
     // If the admin has selected to show all the values then just select all
     // records from the table referenced by the foreign key.
     if ($this->options['show_all']) {
@@ -224,7 +224,7 @@ class chado_views_handler_filter_fk extends views_handler_filter {
         '!name_field' => $name_field
       ));
     }
-    
+
     $resource = chado_query($sql);
     $options = array();
 
@@ -261,14 +261,14 @@ class chado_views_handler_filter_fk extends views_handler_filter {
       ),
       '#default_value' => $this->options['values_form_type'],
     );
-    
+
     $form['show_all'] = array(
       '#type' => 'checkbox',
       '#title' => t('Show All'),
       '#description' => t('When selected all records from the parent table will be shown in the drop-down rather than just those used in the current table.'),
       '#default_value' => $this->options['show_all'],
     );
- 
+
     $form['select_multiple'] = array(
       '#type' => 'checkbox',
       '#title' => t('Select Multiple'),
@@ -299,7 +299,7 @@ class chado_views_handler_filter_fk extends views_handler_filter {
       '#options' => $options,
       '#default_value' => $this->options['display_column'],
     );
-    
+
     $form['max_length'] = array(
       '#type' => 'textfield',
       '#title' => t('Max Width'),
@@ -334,7 +334,7 @@ class chado_views_handler_filter_fk extends views_handler_filter {
       return check_plain((string) $this->operator) . ' ' . check_plain((string) $this->value);
     }
   }
-  
+
   /**
    * {@inheritdoc}
    */
@@ -360,7 +360,7 @@ class chado_views_handler_filter_fk extends views_handler_filter {
       'bool' => TRUE,
       'export' => TRUE,
     );
-    
+
     // display column.
     $table_defn = chado_get_schema($this->definition['foreign_key']['right_table']);
     $fields = array_keys($table_defn['fields']);
@@ -390,7 +390,7 @@ class chado_views_handler_filter_fk extends views_handler_filter {
 class chado_views_handler_filter_string extends views_handler_filter_string {
 
   function query() {
-    
+
     // Adds joins to chado_entity and the chado table this field is from.
     $alias = _chado_views_add_table_joins($this);
 
@@ -414,7 +414,7 @@ class chado_views_handler_filter_string extends views_handler_filter_string {
  */
 function _chado_views_add_table_joins(&$handler) {
 
-  // First we need to join to the chado_entity table where the link between an 
+  // First we need to join to the chado_entity table where the link between an
   // entity and it's chado record is stored.
   $join = new views_join();
   $join->construct('chado_entity', $handler->table, 'id', 'chado_entity_id');
@@ -422,7 +422,7 @@ function _chado_views_add_table_joins(&$handler) {
 
   // Restrict the chado_entity join to only return the table this field is from.
   $handler->query->add_where(0, $alias .'.data_table', $handler->definition['chado_table'], '=');
-  
+
   // Now, we need to join from chado_entity to the chado table needed by this field.
   // This only works if the field is from the base table.
   // @todo: fix handler to work with non-base tables.

+ 8 - 0
tripal_chado/includes/fields/chado_base__organism_id.inc

@@ -242,6 +242,14 @@ class chado_base__organism_id extends TripalField {
 
     return $element;
   }
+
+
+  /**
+   * @see TripalField::views_data()
+   */
+  public function views_data_alter(&$data, $field, $entity_info) {
+    dpm($data);
+  }
 }
 
 

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

@@ -253,7 +253,8 @@ function tripal_chado_entity_property_get_value($entity, $options, $field_name,
   // @todo: handle fields with multiple values.
   else {
     $render_array = field_view_value($entity_type, $entity, $field_name, $items[0], $display, $langcode);
-    drupal_set_message('Tripal Chado currently only supports views integration for single value fields. The first value has been shown.', 'warning');
+    drupal_set_message('Tripal Chado currently only supports views integration ' .
+      'for single value fields. The first value has been shown.', 'warning');
   }
 
   return drupal_render($render_array);

+ 40 - 27
tripal_chado/includes/tripal_chado.fields.inc

@@ -560,13 +560,45 @@ function tripal_chado_field_is_empty($item, $field) {
   return TRUE;
 }
 
-
+/**
+ * Implements hook_update_bundle_fields().
+ *
+ */
+function tripal_chado_update_bundle_fields($entity_type, $bundle, $term) {
+  // Get the list of fields that should be attached to this bundle and
+  // add them.
+  $bundle_name = $bundle->name;
+  $fields = tripal_chado_get_bundle_fields($entity_type, $bundle, $term);
+  foreach ($fields as $field_name => $field_info) {
+    tripal_update_bundle_field($field_name, $field_info, $entity_type, $bundle_name);
+  }
+}
 
 /**
  * Implements hook_add_bundle_fields().
  */
 function tripal_chado_add_bundle_fields($entity_type, $bundle, $term) {
 
+  // Get the list of fields that should be attached to this bundle and
+  // add them.
+  $bundle_name = $bundle->name;
+  $fields = tripal_chado_get_bundle_fields($entity_type, $bundle, $term);
+  foreach ($fields as $field_name => $field_info) {
+    tripal_add_bundle_field($field_name, $field_info, $entity_type, $bundle_name);
+  }
+}
+/**
+ * Retreives a list of the fields that should be attached to the bundle.
+ *
+ * @return
+ *   An associative array of fields to attach to the bundle. The keys are the
+ *   field names and the values is an info array that can be passed to the
+ *   tripal_add_bundle_field() function.
+ */
+function tripal_chado_get_bundle_fields($entity_type, $bundle, $term) {
+
+  $fields = array();
+
   $bundle_name = $bundle->name;
 
   // This array will hold details that map the bundle to tables in Chado.
@@ -642,27 +674,6 @@ function tripal_chado_add_bundle_fields($entity_type, $bundle, $term) {
   tripal_set_bundle_variable('chado_table', $bundle->id, $bundle_data['data_table']);
   tripal_set_bundle_variable('chado_column', $bundle->id, $bundle_data['field']);
 
-
-/*   // Call the hook_attach_info() for all Chado fields to see if any of them
-  // want to attach themsevles to this bundle.
-  // Iterate through the fields, include the file and run the info function.
-  $fields_path = drupal_get_path('module', 'tripal_chado') . '/includes/fields';
-  $field_files = file_scan_directory($fields_path, '/^chado_.*\.inc$/');
-  foreach ($field_files as $file) {
-    $field_type = $file->name;
-    module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);
-    $function = $field_type . '_attach_info';
-    if (function_exists($function)) {
-      // Get the field info.
-      $field_info = $function($entity_type, $bundle, $bundle_data);
-      if (!is_array($field_info) or count(array_keys($field_info)) == 0) {
-        continue;
-      }
-      $field_name = $field_info['field_name'];
-      tripal_add_bundle_field($field_name, $field_info, $entity_type, $bundle_name);
-    }
-  } */
-
   // Find all of the files in the tripal_chado/includes/fields directory.
   $fields_path = drupal_get_path('module', 'tripal_chado') . '/includes/fields';
   $field_files = file_scan_directory($fields_path, '/^chado_.*\.inc$/');
@@ -686,21 +697,22 @@ function tripal_chado_add_bundle_fields($entity_type, $bundle, $term) {
       continue;
     }
     $field_name = $field_info['field_name'];
-    tripal_add_bundle_field($field_name, $field_info, $entity_type, $bundle_name);
+
+    $fields[$field_name] = $field_info;
   }
 
   // Adds any remaining base fields that may not have been dealt with
   // by a custom field.
-  tripal_chado_add_bundle_fields_base__fields($entity_type, $bundle_name, $bundle_data);
-
+  tripal_chado_add_bundle_fields_base__fields($fields, $entity_type, $bundle_name, $bundle_data);
 
+  return $fields;
 }
 
 
 /**
  * Adds the fields for the base table to the entity.
  */
-function tripal_chado_add_bundle_fields_base__fields($entity_type_name, $bundle_name, $bundle_data) {
+function tripal_chado_add_bundle_fields_base__fields(&$fields, $entity_type_name, $bundle_name, $bundle_data) {
 
   $table_name = $bundle_data['data_table'];
   $type_table = $bundle_data['type_table'];
@@ -757,7 +769,8 @@ function tripal_chado_add_bundle_fields_base__fields($entity_type_name, $bundle_
     }
 
     // Add the field to the bundle.
-    tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
+    $fields[$field_name] = $field_info;
+    //tripal_add_bundle_field($field_name, $field_info, $entity_type_name, $bundle_name);
   }
 }
 

+ 49 - 40
tripal_chado/tripal_chado.views.inc

@@ -33,7 +33,7 @@ function tripal_chado_views_data_alter(&$data) {
   return $data;
 }
 
-/** 
+/**
  * Adds integration for chado-based fields.
  *
  * We can't use hook_field_view_data since this only works when the
@@ -42,12 +42,16 @@ function tripal_chado_views_data_alter(&$data) {
  * for our storage engine.
  */
 function tripal_chado_add_field_views_data(&$data) {
-
+return;
   foreach (field_info_fields() as $field) {
     if ($field['storage']['type'] != 'field_chado_storage') {
       continue;
     }
 
+    $field_name = $field['field_name'];
+    $field_type = $field['type'];
+
+
     // Currently, we only handle integration of chado fields with TripalEntity.
     // @todo: extend this to work with other entities in the future.
     if (isset($field['bundles']['TripalEntity']) AND isset($field['settings']['chado_column'])) {
@@ -60,12 +64,12 @@ function tripal_chado_add_field_views_data(&$data) {
       if (preg_match('/prop$/', $field['settings']['chado_table'])) {
         continue;
       }
-      
+
       // Get some information about the chado table in order to make good
-      // choices for handlers.
+      // default choices for handlers.
       $table_desc = chado_get_schema($field['settings']['chado_table']);
       $field_defn = $table_desc['fields'][ $field['settings']['chado_column'] ];
-      
+
       // We also need to know if this field is a foreign key.
       $fk_defn = FALSE;
       foreach ($table_desc['foreign keys'] as $details) {
@@ -80,13 +84,12 @@ function tripal_chado_add_field_views_data(&$data) {
           }
         }
       }
-      
 
-      // Unfortunatly we can't use the field label since that is set at the 
+      // Unfortunatly we can't use the field label since that is set at the
       // instance level and fields are integrated at the field level (independant of bundle).
       // Thus we will simply make the most readable and informative field name we can.
-      $data['tripal_entity'][ $field['field_name'] ]['title'] = ucfirst(str_replace('_',' ',$field['settings']['chado_table']))
-        . ' ' .ucfirst(str_replace('_',' ',$field['settings']['chado_column']));
+      $data['tripal_entity'][$field_name]['title'] = ucfirst(str_replace('_',' ',$field['settings']['chado_table']))
+        . ': ' .ucfirst(str_replace('_',' ',$field['settings']['chado_column']));
 
       // The help should be 'Appears in: TripalEntity: gene, organism'
       // so that users know where they can use it. This requires a little extra work since all
@@ -97,51 +100,57 @@ function tripal_chado_add_field_views_data(&$data) {
       foreach ($field['bundles']['TripalEntity'] as $bundle_id) {
         $bundle_labels[] = $entity_info['bundles'][$bundle_id]['label'];
       }
-      $data['tripal_entity'][ $field['field_name'] ]['help'] = 'Appears in: TripalEntity:' . implode(', ', $bundle_labels);
+      $data['tripal_entity'][$field_name]['help'] = 'Appears in: TripalEntity:' . implode(', ', $bundle_labels);
 
       // Define the field.
-      $data['tripal_entity'][ $field['field_name'] ]['field']['chado_field'] = $field['settings']['chado_column'];
-      $data['tripal_entity'][ $field['field_name'] ]['field']['chado_table'] = $field['settings']['chado_table'];
-      $data['tripal_entity'][ $field['field_name'] ]['field']['field_name'] = $field['field_name'];
-      $data['tripal_entity'][ $field['field_name'] ]['field']['entity_table'] = 'tripal_entity';
-      $data['tripal_entity'][ $field['field_name'] ]['field']['entity_type'] = 'TripalEntity';
-      $data['tripal_entity'][ $field['field_name'] ]['field']['bundles'] = $field['bundles']['TripalEntity'];
-      $data['tripal_entity'][ $field['field_name'] ]['field']['handler'] = 'chado_views_handler_field';
-      $data['tripal_entity'][ $field['field_name'] ]['field']['click sortable'] = FALSE;
+      $data['tripal_entity'][$field_name]['field']['chado_field'] = $field['settings']['chado_column'];
+      $data['tripal_entity'][$field_name]['field']['chado_table'] = $field['settings']['chado_table'];
+      $data['tripal_entity'][$field_name]['field']['field_name'] = $field['field_name'];
+      $data['tripal_entity'][$field_name]['field']['entity_table'] = 'tripal_entity';
+      $data['tripal_entity'][$field_name]['field']['entity_type'] = 'TripalEntity';
+      $data['tripal_entity'][$field_name]['field']['bundles'] = $field['bundles']['TripalEntity'];
+      $data['tripal_entity'][$field_name]['field']['handler'] = 'chado_views_handler_field';
+      $data['tripal_entity'][$field_name]['field']['click sortable'] = FALSE;
 
       // Define the Filter.
-      $data['tripal_entity'][ $field['field_name'] ]['filter']['chado_field'] = $field['settings']['chado_column'];
-      $data['tripal_entity'][ $field['field_name'] ]['filter']['chado_table'] = $field['settings']['chado_table'];
-      $data['tripal_entity'][ $field['field_name'] ]['filter']['field_name'] = $field['field_name'];
-      $data['tripal_entity'][ $field['field_name'] ]['filter']['entity_table'] = 'tripal_entity';
-      $data['tripal_entity'][ $field['field_name'] ]['filter']['entity_type'] = 'TripalEntity';
-      $data['tripal_entity'][ $field['field_name'] ]['filter']['bundles'] = $field['bundles']['TripalEntity'];
-      $data['tripal_entity'][ $field['field_name'] ]['filter']['handler'] = 'chado_views_handler_filter_string';
+      $data['tripal_entity'][$field_name]['filter']['chado_field'] = $field['settings']['chado_column'];
+      $data['tripal_entity'][$field_name]['filter']['chado_table'] = $field['settings']['chado_table'];
+      $data['tripal_entity'][$field_name]['filter']['field_name'] = $field['field_name'];
+      $data['tripal_entity'][$field_name]['filter']['entity_table'] = 'tripal_entity';
+      $data['tripal_entity'][$field_name]['filter']['entity_type'] = 'TripalEntity';
+      $data['tripal_entity'][$field_name]['filter']['bundles'] = $field['bundles']['TripalEntity'];
+      $data['tripal_entity'][$field_name]['filter']['handler'] = 'chado_views_handler_filter_string';
 
       // Define sorting.
-      $data['tripal_entity'][ $field['field_name'] ]['sort']['chado_field'] = $field['settings']['chado_column'];
-      $data['tripal_entity'][ $field['field_name'] ]['sort']['chado_table'] = $field['settings']['chado_table'];
-      $data['tripal_entity'][ $field['field_name'] ]['sort']['field_name'] = $field['field_name'];
-      $data['tripal_entity'][ $field['field_name'] ]['sort']['entity_table'] = 'tripal_entity';
-      $data['tripal_entity'][ $field['field_name'] ]['sort']['entity_type'] = 'TripalEntity';
-      $data['tripal_entity'][ $field['field_name'] ]['sort']['bundles'] = $field['bundles']['TripalEntity'];
-      $data['tripal_entity'][ $field['field_name'] ]['sort']['handler'] = 'chado_views_handler_sort';
-      
+      $data['tripal_entity'][$field_name]['sort']['chado_field'] = $field['settings']['chado_column'];
+      $data['tripal_entity'][$field_name]['sort']['chado_table'] = $field['settings']['chado_table'];
+      $data['tripal_entity'][$field_name]['sort']['field_name'] = $field['field_name'];
+      $data['tripal_entity'][$field_name]['sort']['entity_table'] = 'tripal_entity';
+      $data['tripal_entity'][$field_name]['sort']['entity_type'] = 'TripalEntity';
+      $data['tripal_entity'][$field_name]['sort']['bundles'] = $field['bundles']['TripalEntity'];
+      $data['tripal_entity'][$field_name]['sort']['handler'] = 'chado_views_handler_sort';
+
       // Specify special handlers.
       if ($fk_defn) {
-        $data['tripal_entity'][ $field['field_name'] ]['filter']['handler'] = 'chado_views_handler_filter_fk';
-        $data['tripal_entity'][ $field['field_name'] ]['filter']['foreign_key'] = $fk_defn;
+        $data['tripal_entity'][$field_name]['filter']['handler'] = 'chado_views_handler_filter_fk';
+        $data['tripal_entity'][$field_name]['filter']['foreign_key'] = $fk_defn;
       }
       if ($field_defn['type'] == 'boolean') {
-        $data['tripal_entity'][ $field['field_name'] ]['filter']['handler'] = 'chado_views_handler_filter_boolean';
-        $data['tripal_entity'][ $field['field_name'] ]['filter']['label'] = $field['settings']['chado_column'];
-        $data['tripal_entity'][ $field['field_name'] ]['filter']['type'] = 'yes-no'; 
+        $data['tripal_entity'][$field_name]['filter']['handler'] = 'chado_views_handler_filter_boolean';
+        $data['tripal_entity'][$field_name]['filter']['label'] = $field['settings']['chado_column'];
+        $data['tripal_entity'][$field_name]['filter']['type'] = 'yes-no';
       }
       elseif ($field_defn['type'] == 'datetime') {
-        $data['tripal_entity'][ $field['field_name'] ]['filter']['handler'] = 'chado_views_handler_filter_date';
+        $data['tripal_entity'][$field_name]['filter']['handler'] = 'chado_views_handler_filter_date';
       }
 
-    }    
+      // Allow the fields to alter the default selections from above.
+      module_load_include('inc', 'tripal_chado', 'includes/fields/' . $field_type);
+      if (preg_match('/^chado/', $field_type) and class_exists($field_type)) {
+        $field_obj = new $field_type();
+        $field_obj->views_data_alter($data['tripal_entity'][$field_name], $field, $entity_info);
+      }
+    }
   }
 }