You are here

function content_views_field_tables in Content Construction Kit (CCK) 5

2 calls to content_views_field_tables()
content_views_tables in ./content_views.inc
Implementation of hook_views_tables().
hook_field_settings in ./field.php
Handle the parameters for a field.

File

./content_views.inc, line 29
Interface between content.module and views.module.

Code

function content_views_field_tables($field) {
  $field_types = _content_field_types();
  $db_info = content_database_info($field);
  if (count($db_info['columns'])) {
    $table = array();
    $table['name'] = $db_info['table'];
    $table['join'] = array(
      'left' => array(
        'table' => 'node',
        'field' => 'vid',
      ),
      'right' => array(
        'field' => 'vid',
      ),
    );
    $module = $field_types[$field['type']]['module'];
    $formatters = array();
    if (is_array($field_types[$field['type']]['formatters'])) {
      foreach ($field_types[$field['type']]['formatters'] as $name => $info) {
        $formatters[$name] = $info['label'];
      }
    }
    $columns = $db_info['columns'];
    $main_column = array_shift($columns);
    $addlfields = array();
    foreach ($columns as $column => $attributes) {
      $addlfields[] = $attributes['column'];
    }
    if ($field['multiple']) {
      $addlfields[] = 'delta';
    }
    $table['fields'] = array();
    $table['fields'][$main_column['column']] = array(
      'name' => $field_types[$field['type']]['label'] . ': ' . $field['widget']['label'] . ' (' . $field['field_name'] . ')',
      'addlfields' => $addlfields,
      'sortable' => isset($main_column['sortable']) ? $main_column['sortable'] : FALSE,
      'query_handler' => 'content_views_field_query_handler',
      'handler' => array(
        'content_views_field_handler_group' => t('Group multiple values'),
        'content_views_field_handler_ungroup' => t('Do not group multiple values'),
        'content_views_field_handler_first' => t('Show first value only'),
        'content_views_field_handler_last' => t('Show last value only'),
      ),
      'option' => array(
        '#type' => 'select',
        '#options' => $formatters,
      ),
      'content_db_info' => $db_info,
      'content_field' => $field,
      'content_field_module' => $module,
    );
    if (isset($main_column['sortable']) && $main_column['sortable']) {
      $table['sorts'] = array();
      $table['sorts'][$main_column['column']] = array(
        'name' => $field_types[$field['type']]['label'] . ': ' . $field['widget']['label'] . ' (' . $field['field_name'] . ')',
        'field' => $main_column['column'],
        'content_db_info' => $db_info,
        'content_field' => $field,
        'content_field_module' => $module,
      );
    }
    $filters = module_invoke($module, 'field_settings', 'filters', $field);
    if (is_array($filters) && count($filters)) {
      $table['filters'] = array();
      foreach ($filters as $key => $filter) {
        $filter_name = '';
        if (count($filters) > 1) {
          $filter_name = !empty($filter['name']) ? $filter['name'] : $key;
          $filter_name = ' - ' . $filter_name;
        }
        $name = $field_types[$field['type']]['label'] . ': ' . $field['widget']['label'] . $filter_name . ' (' . $field['field_name'] . ')';
        $init = array(
          'name' => $name,
          'field' => $main_column['column'],
          'content_db_info' => $db_info,
          'content_field' => $field,
          'content_field_module' => $module,
        );
        $table['filters'][$main_column['column'] . '_' . $key] = array_merge($filter, $init);
      }
    }

    // We don't use $db_info['table'] for the key, since that may change during
    // the lifetime of the field and we don't want to require users to redefine
    // their views.
    return array(
      'node_data_' . $field['field_name'] => $table,
    );
  }
}