function flipping_book_reference_field_views_data in Flipping Book 7
Implements hook_field_views_data().
In addition to the default field information we add the relationship for views to connect back to the flipping_book table.
File
- ./
flipping_book_reference.module, line 708 - Defines a field type for referencing one flipping_book from a node.
Code
function flipping_book_reference_field_views_data($field) {
// No module_load_include(): this hook is invoked from
// views/modules/field.views.inc, which is where that function is defined.
$data = field_views_field_default_views_data($field);
$storage = $field['storage']['details']['sql'];
foreach ($storage as $table_data) {
$table = key($table_data);
$columns = current($table_data);
$id_column = $columns['fbid'];
if (isset($data[$table])) {
// Filter: swap the handler to the 'in' operator. The callback receives
// the field name instead of the whole $field structure to keep views
// data to a reasonable size.
$data[$table][$id_column]['filter']['handler'] = 'views_handler_filter_in_operator';
$data[$table][$id_column]['filter']['options callback'] = 'flipping_book_reference_views_filter_options';
$data[$table][$id_column]['filter']['options arguments'] = array(
$field['field_name'],
);
// Argument: display flipping_book.title in argument titles (handled in
// our custom handler) and summary lists (handled by the base
// views_handler_argument handler).
// Both mechanisms rely on the 'name table' and 'name field' information
// below, by joining to a separate copy of the base table from the field
// data table.
$data[$table][$id_column]['argument']['handler'] = 'references_handler_argument';
$data[$table][$id_column]['argument']['name table'] = $table . '_reference';
$data[$table][$id_column]['argument']['name field'] = 'title';
$data[$table . '_reference']['table']['join'][$table] = array(
'left_field' => $id_column,
'table' => 'flipping_book',
'field' => 'fbid',
);
// Relationship.
$data[$table][$id_column]['relationship'] = array(
'handler' => 'references_handler_relationship',
'base' => 'flipping_book',
'base field' => 'fbid',
'field' => $id_column,
'label' => $field['field_name'],
'field_name' => $field['field_name'],
);
}
}
return $data;
}