public function views_handler_filter_dynamic_fields::pre_query in Views Dynamic Fields 7
Exclude fields from the view before the query is run.
Overrides views_handler::pre_query
See also
\views\handler\views_handler::pre_query()
File
- handlers/
views_handler_filter_dynamic_fields.inc, line 461 - Views dynamic fields filter handler.
Class
- views_handler_filter_dynamic_fields
- Simple filter to pick and choose the fields to show in the view.
Code
public function pre_query() {
// Fields submitted by user in the exposed filter.
$exposed_input = $this->view
->get_exposed_input();
if (isset($exposed_input[$this->options['expose']['identifier']])) {
$exposed_input_fields = $exposed_input[$this->options['expose']['identifier']];
}
$defaults_filterable_fields = array_filter($this->options['defaults_filterable_fields']);
$filterable_fields = array_filter($this->options['filterable_fields']);
// Get all fields.
foreach ($this->view->field as $field_name => $field) {
$field_names[] = $field_name;
// Default view when no filtering is applied.
if (empty($exposed_input_fields)) {
if (!in_array($field_name, array_keys($defaults_filterable_fields)) && isset($filterable_fields[$field_name])) {
$this->view->field[$field_name]->options['exclude'] = 1;
}
}
}
if (!empty($exposed_input_fields)) {
// Exclude these fields.
$combined_fields = isset($exposed_input['combined']) ? unserialize($exposed_input['combined']) : array();
if (!$this->options['checkboxes']) {
$this
->pre_query_single($exposed_input, $field_names, $combined_fields);
}
else {
$this
->pre_query_multiple($exposed_input, $field_names, $combined_fields);
}
}
}