You are here

function data_get_table_field_views_data in Data 7

Get the hook_views_data() declaration for a field and handler type.

Helper for our hook_views_data().

Parameters

$type: The view handler type ('field', 'filter', 'sort', 'argument').

$table: A data table object.

$field_name: String: name of the field.

$default: Boolean for whether to return the default handler for the given db column type.

Return value

An array for a hook_views_data() handler declaration.

See also

data_views_data()

1 call to data_get_table_field_views_data()
data_views_data in ./data.views.inc
Implements hook_views_data().

File

./data.views.inc, line 100
Views hooks and utility functions.

Code

function data_get_table_field_views_data($type, $table, $field_name, $default = FALSE) {
  $schema = $table
    ->get('table_schema');
  $meta = $table
    ->get('meta');

  // If there is no label, generate one from field name.
  $title = empty($meta['fields'][$field_name]['label']) ? data_natural_name($field_name) : $meta['fields'][$field_name]['label'];
  switch ($type) {
    case 'field':
      $views_data = array(
        'handler' => data_get_views_handler('field', $table, $field_name),
        'help' => $title,
        'click sortable' => TRUE,
      );

      // Extra options.
      // Configure the Views numeric field handler to offer options for decimal
      // numbers.
      if ($views_data['handler'] == 'views_handler_field_numeric') {
        if ($schema['fields'][$field_name]['type'] == 'float' || $schema['fields'][$field_name]['type'] == 'numeric') {
          $views_data['float'] = TRUE;
        }
      }
      break;
    case 'filter':
      $views_data = array(
        'handler' => data_get_views_handler('filter', $table, $field_name),
        'allow empty' => TRUE,
        'help' => t('Filter on %field', array(
          '%field' => $title,
        )),
      );
      break;
    case 'argument':
      $views_data = array(
        'handler' => data_get_views_handler('argument', $table, $field_name),
        'help' => $title,
      );
      break;
    case 'sort':
      $views_data = array(
        'handler' => data_get_views_handler('sort', $table, $field_name),
        'help' => t('Sort by %field', array(
          '%field' => $title,
        )),
      );
      break;
  }
  if (isset($meta['fields'][$field_name]['date'])) {
    if (!empty($meta['fields'][$field_name]['date']['sql_type'])) {
      $views_data['is date'] = TRUE;
    }
  }
  return $views_data;
}