function _office_hours_views_field_views_data in Office Hours 6
Same name and namespace in other branches
- 6.2 office_hours.module \_office_hours_views_field_views_data()
Adding all table field into $data in hook_views_data.
1 call to _office_hours_views_field_views_data()
- office_hours_field_settings in ./
office_hours.module - Implementation of hook_field_settings().
File
- ./
office_hours.module, line 418 - Creates a field and widget for inserting working or office hours per day
Code
function _office_hours_views_field_views_data($field) {
$field_types = _content_field_types();
$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']])) {
$types[] = $type['name'];
}
}
$data = array();
$data['table']['group'] = t('Content');
$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 '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[] = class_exists('views_handler_filter_float') ? 'content_handler_filter_float' : 'content_handler_filter_numeric';
$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;
}
}
$i = 0;
// Ensure all columns are retrieved,
$additional_fields = drupal_map_assoc($columns);
foreach ($columns as $key => $column) {
list(, , $field_type) = explode('_', $column);
$data[$column] = array(
'group' => t('Content'),
'title' => t('@label : @widget', array(
'@label' => $field_types[$field['type']]['label'],
'@widget' => $field['widget']['label'],
)),
//. ' (' . $field['field_name'] . ' ' . $field_type . ')',
'help' => t($field_types[$field['type']]['label']) . ' - ' . t('Appears in: @types', array(
'@types' => implode(', ', $types),
)),
'field' => array(
'field' => $column,
'table' => $db_info['table'],
'handler' => 'content_handler_field_multiple',
'click sortable' => $sorts[$i],
// 'additional fields' => $additional_fields,
'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' => $column,
'table' => $db_info['table'],
'handler' => $arguments[$i],
'click sortable' => $sorts[$i],
// TODO used in once place in node.views.inc, should we use it here?
'name field' => '',
// TODO
//'additional fields' => $additional_fields,
'content_field_name' => $field['field_name'],
'empty field name' => t('<No value>'),
'allow empty' => TRUE,
),
'filter' => array(
'field' => $column,
'title' => t($field['widget']['label']) . ': ' . $field_type,
'table' => $db_info['table'],
'handler' => $filters[$i],
//'additional fields' => $additional_fields,
'content_field_name' => $field['field_name'],
'allow empty' => TRUE,
),
);
$i++;
}
// TODO do we need different handling for sorts with Views 2,
// especially when relationships are involved?
if (!empty($sorts[$i])) {
$data[$column]['sort'] = array(
'field' => $column,
'table' => $db_info['table'],
'handler' => 'content_handler_sort',
// 'additional fields' => $additional_fields,
'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,
);
}