You are here

function _efq_views_get_field_handlers in EntityFieldQuery Views Backend 7

Helper for efq_views_views_data() Returns defined fields & their columns for the given entity type (or, if absent, all entity types).

Based on field_views_field_default_views_data() from field.views.inc

1 call to _efq_views_get_field_handlers()
efq_views_views_data in ./efq_views.views.inc
Implements hook_views_data().

File

./efq_views.views.inc, line 205

Code

function _efq_views_get_field_handlers(&$views_data, $field_name) {
  $column = FALSE;
  if (isset($views_data['real field'])) {
    list($field_name, $column) = explode(':', $views_data['real field']);
  }

  // Something bogus.
  if (!($field = field_info_field($field_name))) {
    return;
  }
  if (!$column) {

    // This will be handled later when a real field props up.
    if (count($field['columns']) > 1) {
      return;
    }
    $columns = array_keys($field['columns']);
    $column = reset($columns);
  }
  if (!isset($field['columns'][$column])) {

    // Computed field.
    return;
  }
  $allow_sort = TRUE;

  // Identify likely filters and arguments for each column based on field type.
  switch ($field['columns'][$column]['type']) {
    case 'int':
    case 'mediumint':
    case 'tinyint':
    case 'bigint':
    case 'serial':
    case 'numeric':
    case 'float':
      $filter = 'efq_views_handler_filter_field_numeric';
      $argument = 'efq_views_handler_argument_field_numeric';
      break;
    case 'text':
    case 'blob':

      // It does not make sense to sort by blob or text.
      $allow_sort = FALSE;
    default:
      $filter = 'efq_views_handler_filter_field_string';
      $argument = 'efq_views_handler_argument_field_string';
      break;
  }
  switch ($field['module']) {
    case 'date':
      $filter = 'efq_views_handler_filter_field_date';
      break;
    case 'list':
      $filter = 'efq_views_handler_filter_field_list';
      break;
    case 'taxonomy':
      $filter = 'efq_views_handler_filter_term_reference';
      $argument = 'efq_views_handler_argument_field_numeric';
      break;
  }
  $views_data['argument'] = array(
    'field' => $column,
    'handler' => $argument,
    'field_name' => $field['field_name'],
    'empty field name' => t('<No value>'),
  );
  $views_data['filter'] = array(
    'field' => $column,
    'handler' => $filter,
    'field_name' => $field_name,
    'allow empty' => TRUE,
  );
  $views_data['field']['click sortable'] = $allow_sort;
  if (!empty($allow_sort)) {
    $views_data['sort'] = array(
      'field' => $column,
      'handler' => 'efq_views_handler_sort_field',
      'field_name' => $field_name,
    );
  }
}