You are here

function content_views_field_views_data in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 6.3 includes/views/content.views.inc \content_views_field_views_data()
  2. 6.2 includes/views/content.views.inc \content_views_field_views_data()
5 calls to content_views_field_views_data()
content_views_data in includes/content.views.inc
Implementation of hook_views_data().
nodereference_field_settings in modules/nodereference/nodereference.module
Implementation of hook_field_settings().
number_field_settings in modules/number/number.module
Implementation of hook_field_settings().
text_field_settings in modules/text/text.module
Implementation of hook_field_settings().
userreference_field_settings in modules/userreference/userreference.module
Implementation of hook_field_settings().

File

includes/content.views.inc, line 39

Code

function content_views_field_views_data($field) {
  $field_types = _content_field_types();

  // Check the field module is available.
  // TODO : is this really how we should do it ?
  if (isset($field_types[$field['type']])) {
    $db_info = content_database_info($field);
    $table_alias = content_views_tablename($field);
    $types = array();
    foreach (content_types() as $type) {
      if (isset($type['fields'][$field['field_name']])) {
        $types[] = $type['name'];
      }
    }
    $data = array();
    $data['table']['group'] = $field_types[$field['type']]['label'];
    $data['table']['join']['node'] = array(
      'table' => $db_info['table'],
      'left_field' => 'vid',
      'field' => 'vid',
    );
    $columns = array();
    $arguments = array();
    $filters = array();
    foreach ($db_info['columns'] as $column => $attributes) {
      $columns[] = $attributes['column'];
      $sorts[] = !empty($attributes['sortable']) ? TRUE : FALSE;

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

        // TODO add markup handlers for these types
        default:
          $filters[] = 'views_handler_filter_string_content';
          $arguments[] = 'views_handler_argument_string_content';
          break;
      }
    }
    $data[$columns[0]] = array(
      'group' => t($field_types[$field['type']]['label']),
      'title' => t($field['widget']['label']) . ' (' . $field['field_name'] . ')',
      'help' => t($field_types[$field['type']]['label']) . ' - ' . t('Appears in : @types', array(
        '@types' => implode(', ', $types),
      )),
      'field' => array(
        'field' => $columns[0],
        'tablename' => $db_info['table'],
        'handler' => 'views_handler_field_content_multiple',
        'click sortable' => $sorts[0],
        'additional fields' => $columns,
        'content_field_name' => $field['field_name'],
        'allow_empty' => TRUE,
        // Access control modules should implement content_views_access_callback().
        'access callback' => 'content_views_access_callback',
        'access arguments' => array(
          $field,
        ),
      ),
      'argument' => array(
        'field' => $columns[0],
        'tablename' => $db_info['table'],
        'handler' => $arguments[0],
        'click sortable' => $sorts[0],
        // TODO used in once place in node.views.inc, should we use it here?
        'name field' => '',
        // TODO
        'additional fields' => $columns,
        'content_field_name' => $field['field_name'],
        'allow_empty' => TRUE,
      ),
      'filter' => array(
        'field' => $columns[0],
        'title' => t($field['widget']['label']),
        'tablename' => $db_info['table'],
        'handler' => $filters[0],
        'additional fields' => $columns,
        'content_field_name' => $field['field_name'],
        'allow_empty' => TRUE,
      ),
    );

    // TODO do we need different handling for sorts with Views 2,
    // especially when relationships are involved?
    if (!empty($sorts[0])) {
      $data[$columns[0]]['sort'] = array(
        'field' => $columns[0],
        'tablename' => $db_info['table'],
        'handler' => 'views_handler_sort_content',
        'additional fields' => $columns,
        'content_field_name' => $field['field_name'],
        'allow_empty' => TRUE,
      );
    }

    // TODO : provide automatic filters, sorts, and arguments for each column, not just the first?
    return array(
      $table_alias => $data,
    );
  }
}