protected function TripalField::_addViewsDataElement

3.x TripalField.inc protected TripalField::_addViewsDataElement(&$data, $view_base_id, $parent, $element_name, $element_details)

Parameters

unknown $data:

unknown $view_base_id:

unknown $parent:

unknown $element_name:

unknown $element_details:

1 call to TripalField::_addViewsDataElement()
TripalField::viewsData in tripal/includes/TripalFields/TripalField.inc
Describes this field to Views.

File

tripal/includes/TripalFields/TripalField.inc, line 388

Class

TripalField

Code

protected function _addViewsDataElement(&$data, $view_base_id, $parent, $element_name, $element_details) {
  // Skip the 'entity' element, as we'll never make this searchable or
  // viewable. It's meant for linking.
  if ($element_name == 'entity') {
    return;
  }

  if (!preg_match('/:/', $element_name)) {
    return;
  }

  $field_name = $parent . '.' . $element_name;
  list($vocabulary, $accession) = explode(':', $element_name);
  $term = tripal_get_term_details($vocabulary, $accession);

  // Get any titles or help text that is overriden.
  $title = ucfirst($term['name']);
  if (array_key_exists('label', $element_details)) {
    $title = $element_details['label'];
  }
  $help = $term['definition'];
  if (array_key_exists('help', $element_details)) {
    $help = $element_details['help'];
  }

  // Build the entry for the field.
  $data[$view_base_id][$field_name] = array(
    'title' => $title,
    'help' => $help,
    'field' => array(
      'handler' => 'tripal_views_handler_field_element',
    ),
  );
  // Is the field sortable?
  if (array_key_exists('sortable', $element_details) and $element_details['sortable']) {
    $data[$view_base_id][$field_name]['sort']['handler'] = 'tripal_views_handler_sort';
    $data[$view_base_id][$field_name]['field']['click sortable'] = TRUE;
  }

  // Is the field searchable?
  if (array_key_exists('searchable', $element_details) and $element_details['searchable']) {
    $filter_handler = 'tripal_views_handler_filter_element_string';
    if (array_key_exists('type', $element_details) and $element_details['type'] == 'numeric') {
      $filter_handler = 'tripal_views_handler_filter_numeric';
    }
    $data[$view_base_id][$field_name]['filter'] = array(
      'handler' => $filter_handler,
    );
  }

  // Recusrively add any entries for child elements.
  if (array_key_exists('elements', $element_details)) {
    $elements = $element_details['elements'];
    foreach ($elements as $element_name => $element_details) {
      $this->_addViewsDataElement($data, $view_base_id, $field_name, $element_name, $element_details);
    }
  }
}