function workbench_access_views_pre_view in Workbench Access 7
Implements hook_view_pre_view().
Dynamically adds the exposed fitlers that workbench_access provides to appropriate Views.
There are a lot of 'if () {} else {}' statements in here to find out which options to target. These look at a given option and check if it uses the default settings or an override. The given option is then modified to add filters/fields/settings from workbench_access.
File
- ./
workbench_access.views.inc, line 86 - Views integration for Workbench Access.
Code
function workbench_access_views_pre_view(&$view, &$display_id, &$args) {
// If not configured, do nothing.
$tree = workbench_access_get_active_tree();
if (empty($tree['active'])) {
return;
}
// Target any view with a workbench tag that uses 'node' as the base_table.
// TODO: support the node_revision table.
if (is_numeric(strripos($view->tag, 'Workbench')) && ($view->base_table == 'node' || $view->base_table == 'node_revision')) {
// This shorthand variable will increase readability.
$current_display = $view->current_display;
// If the current display uses default filters, target them.
if ($current_display == 'default' || $view->display[$current_display]->handler->options['defaults']['filters']) {
$filters =& $view->display['default']->handler->options['filters'];
}
else {
$filters =& $view->display[$current_display]->handler->options['filters'];
}
// Add the access_id filter to the filters array.
$filters['access_id'] = _workbench_access_views_access_id_filter_definition();
// If the current display uses the default style_plugin, target the default
// style_plugin and style options.
if ($current_display == 'default' || $view->display[$current_display]->handler->options['defaults']['style_plugin']) {
$style_plugin =& $view->display['default']->handler->options['style_plugin'];
$style_options =& $view->display['default']->handler->options['style_options'];
}
else {
$style_plugin =& $view->display[$current_display]->handler->options['style_plugin'];
$style_options =& $view->display[$current_display]->handler->options['style_options'];
}
// Only add a section field and style options if this is a table.
if ($style_plugin == 'table') {
// If the current display uses the default fields, target them.
if ($current_display == 'default' || $view->display[$current_display]->handler->options['defaults']['fields']) {
$fields =& $view->display['default']->handler->options['fields'];
}
else {
$fields =& $view->display[$current_display]->handler->options['fields'];
}
// This temporary variable will take all the values from
// the existing fields array and add a section field after the title.
$new_view_fields = array();
foreach ($fields as $key => $value) {
$new_view_fields[$key] = $value;
if ($key == 'title') {
$new_view_fields['section'] = _workbench_access_views_section_field_definition();
}
}
// Set the new fields array on the actual view.
$fields = $new_view_fields;
$style_options['columns']['section'] = 'section';
$style_options['info']['section'] = array(
// Only do a sortable section column on Views using the node table.
// A PDO error occurs with the node_revision table.
'sortable' => $view->base_table == 'node',
'align' => '',
'separator' => '',
);
}
}
}