function content_views_field_views_data in Content Construction Kit (CCK) 6.3
Same name and namespace in other branches
- 6 includes/content.views.inc \content_views_field_views_data()
- 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/
views/ 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/
views/ content.views.inc, line 155 - Interface between content.module and views.module.
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);
// Field modules that do not store data in the database
// should not create views data tables.
if (empty($db_info['columns'])) {
return;
}
$table_alias = content_views_tablename($field);
$types = array();
foreach (content_types() as $type) {
if (isset($type['fields'][$field['field_name']])) {
// TODO : run check_plain here instead of on the imploded string below ?
$types[] = $type['name'];
}
}
$data = array();
$data['table']['group'] = t('Content');
$data['table']['join']['node'] = array(
'table' => $db_info['table'],
'left_field' => 'vid',
'field' => 'vid',
);
$data['table']['join']['node_revisions'] = array(
'table' => $db_info['table'],
'left_field' => 'vid',
'field' => 'vid',
);
// Build the list of columns enabled for default views integration.
$db_columns = array();
$additional_fields = array();
foreach ($db_info['columns'] as $column => $attributes) {
// Select explicitly enabled field columns.
if (!empty($attributes['views'])) {
$db_columns[$column] = $attributes;
}
// Ensure all columns are retrieved.
$additional_fields[$attributes['column']] = $attributes['column'];
}
// Pick up the first column when none has been explicitly enabled
// (pre CCK 2.2 backwards compatibility).
if (empty($db_columns)) {
// Can't use array_slice(), it won't work in PHP4 for assoc array.
foreach ($db_info['columns'] as $column => $attributes) {
$db_columns[$column] = $attributes;
break;
}
}
$columns = array();
$db_fields = array();
$arguments = array();
$filters = array();
foreach ($db_columns as $column => $attributes) {
$columns[] = $column;
$db_fields[] = $attributes['column'];
$sorts[] = !empty($attributes['sortable']) ? TRUE : FALSE;
// Identify likely filters and arguments for each column based on field type.
switch ($attributes['type']) {
case 'int':
case 'mediumint':
case 'tinyint':
case 'bigint':
case 'serial':
$filters[] = 'content_handler_filter_numeric';
$arguments[] = 'content_handler_argument_numeric';
break;
case 'numeric':
case 'float':
$filters[] = 'content_handler_filter_float';
$arguments[] = 'content_handler_argument_numeric';
break;
case 'text':
case 'blob':
// TODO add markup handlers for these types
default:
$filters[] = 'content_handler_filter_string';
$arguments[] = 'content_handler_argument_string';
break;
}
}
// Provide automatic filters, sorts, and arguments for each column, not just the first.
$db_fields_count = count($db_fields);
foreach ($db_fields as $i => $db_field) {
$label_truncated = truncate_utf8(t($field['widget']['label']), 10, TRUE);
if ($db_fields_count == 1) {
$title = t('@label (!name)', array(
'@label' => t($field['widget']['label']),
'!name' => $field['field_name'],
));
$title_short = check_plain($label_truncated);
}
else {
$title = t('@label (!name) - !column', array(
'@label' => t($field['widget']['label']),
'!name' => $field['field_name'],
'!column' => $columns[$i],
));
$title_short = t('@label-truncated - !column', array(
'@label-truncated' => $label_truncated,
'!column' => $columns[$i],
));
}
$data[$db_field] = array(
'group' => t('Content'),
'title' => $title,
'title short' => $title_short,
'help' => t($field_types[$field['type']]['label']) . ' - ' . t('Appears in: @types', array(
'@types' => implode(', ', $types),
)),
);
if ($i == 0) {
$data[$db_field]['field'] = array(
'title' => t('@label (!name)', array(
'@label' => t($field['widget']['label']),
'!name' => $field['field_name'],
)),
'title short' => check_plain($label_truncated),
'field' => $db_field,
'table' => $db_info['table'],
'handler' => 'content_handler_field_multiple',
'click sortable' => $sorts[$i],
'additional fields' => $additional_fields,
'content_field_name' => $field['field_name'],
'access callback' => 'content_access',
'access arguments' => array(
'view',
$field,
),
);
}
$data[$db_field]['argument'] = array(
'field' => $db_field,
'table' => $db_info['table'],
'handler' => $arguments[$i],
'additional fields' => $additional_fields,
'content_field_name' => $field['field_name'],
'empty field name' => t('<No value>'),
);
$data[$db_field]['filter'] = array(
'field' => $db_field,
'table' => $db_info['table'],
'handler' => $filters[$i],
'additional fields' => $additional_fields,
'content_field_name' => $field['field_name'],
'allow empty' => TRUE,
);
if (!empty($sorts[$i])) {
$data[$db_field]['sort'] = array(
'field' => $db_field,
'table' => $db_info['table'],
'handler' => 'content_handler_sort',
'additional fields' => $additional_fields,
'content_field_name' => $field['field_name'],
);
}
}
// Expose additional delta column for multiple value fields.
if ($field['multiple']) {
$title = t('@label (!name) - delta', array(
'@label' => t($field['widget']['label']),
'!name' => $field['field_name'],
));
$title_short = t('@label-truncated - delta', array(
'@label-truncated' => $label_truncated,
));
$db_field = 'delta';
$data[$db_field] = array(
'group' => t('Content'),
'title' => $title,
'title short' => $title_short,
'help' => t('Delta - Appears in: @types', array(
'@types' => implode(', ', $types),
)),
);
$data[$db_field]['field'] = array(
'title' => $title,
'title short' => $title_short,
'field' => $db_field,
'table' => $db_info['table'],
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
'additional fields' => $additional_fields,
'access callback' => 'content_access',
'access arguments' => array(
'view',
$field,
),
);
$data[$db_field]['argument'] = array(
'field' => $db_field,
'table' => $db_info['table'],
'handler' => 'views_handler_argument_numeric',
'additional fields' => $additional_fields,
'empty field name' => t('<No value>'),
);
$data[$db_field]['filter'] = array(
'field' => $db_field,
'table' => $db_info['table'],
'handler' => 'views_handler_filter_numeric',
'additional fields' => $additional_fields,
'allow empty' => TRUE,
);
$data[$db_field]['sort'] = array(
'field' => $db_field,
'table' => $db_info['table'],
'handler' => 'views_handler_sort',
'additional fields' => $additional_fields,
);
}
return array(
$table_alias => $data,
);
}
}