function tripal_views_data_fields

3.x tripal.views.inc tripal_views_data_fields(&$data)

Integreates the Tripal fields with Views.

1 call to tripal_views_data_fields()
tripal_views_data in tripal/tripal.views.inc
Describe various Tripal Core systems to Views

File

tripal/tripal.views.inc, line 96
Integrates many of the core database tables with drupal views

Code

function tripal_views_data_fields(&$data) {

  // Iterate through the fields.
  $fields = field_info_fields();
  foreach ($fields as $field) {

    // Skip fields that aren't attached to TripalEntity entities.
    if (!array_key_exists('TripalEntity', $field['bundles'])) {
      continue;
    }

    // TODO: do we really need this hook? Just substitute the code here
    // for what that hook does... it's only called in one plac.e
    // Call the hook_field_views_data() but only for the tripal module.
    // Otherwise the other modules will expect that this is an SQL-based
    // view.
    $result = (array) module_invoke('tripal', 'field_views_data', $field);

    // Set defaults for the field if no data array was returned.
    if (empty($result)) {
      // Iterate through the bundles to which this field is attached and
      // if it is a TripalField field then we'll call the viewsData function.
      $bundles = $field['bundles']['TripalEntity'];
      $result = array();
      foreach ($bundles as $bundle_name) {
        $field_name = $field['field_name'];

        // Fields should be associated with the bundle's term identifier
        // (i.e. [vocab]__[accession].
        $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
        $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
        $view_base_id = $term->vocab->vocabulary . '__' . $term->accession;

        $instance = field_info_instance('TripalEntity', $field['field_name'], $bundle_name);
        $tfield = new TripalField($field, $instance);
        $result += $tfield->viewsData($view_base_id);
      }
    }

    drupal_alter('field_views_data', $result, $field, $module);

    if (is_array($result)) {
      $data = drupal_array_merge_deep($result, $data);
    }
  }
}