function global_filter_add_view_results in Views Global Filter 8
Same name and namespace in other branches
- 6 global_filter.module \global_filter_add_view_results()
- 7 global_filter.widgets.inc \global_filter_add_view_results()
Add the view results.
2 calls to global_filter_add_view_results()
- global_filter_create_widget in ./
global_filter.widgets.inc - Based on the requested or field-implied widget.
- _global_filter_configure_form in ./
global_filter.blocks.inc - Generates the filter configuration form for filters in a block.
File
- ./
global_filter.widgets.inc, line 386 - global_filter.widgets.inc
Code
function global_filter_add_view_results(&$options, $view_id) {
$view = views_get_view($view_id);
if (!is_object($view)) {
drupal_set_message(t('Global Filter: could not find view: %view.', array(
'%view' => empty($view_id) ? t('no name specified') : $view_id,
)), 'error');
return FALSE;
}
$view
->init_display();
$view
->pre_execute();
$view
->execute();
// Pick the first non-id field of each returned row as the next value for
// the filter.
foreach ($view->result as $row) {
$row_as_array = (array) $row;
foreach ($row_as_array as $fid => $value) {
if ($fid != $view->base_field) {
// E.g. 'nid', 'uid', 'cid', 'tid', 'aid' {accesslog}.
break;
}
}
$key = isset($row_as_array[$view->base_field]) ? $row_as_array[$view->base_field] : NULL;
$options[empty($key) ? $value : $key] = $value;
}
}