function Combine::query
Same name in other branches
- 8.9.x core/modules/views/src/Plugin/views/filter/Combine.php \Drupal\views\Plugin\views\filter\Combine::query()
- 10 core/modules/views/src/Plugin/views/filter/Combine.php \Drupal\views\Plugin\views\filter\Combine::query()
- 11.x core/modules/views/src/Plugin/views/filter/Combine.php \Drupal\views\Plugin\views\filter\Combine::query()
Overrides StringFilter::query
File
-
core/
modules/ views/ src/ Plugin/ views/ filter/ Combine.php, line 58
Class
- Combine
- Filter handler which allows to search on multiple fields.
Namespace
Drupal\views\Plugin\views\filterCode
public function query() {
$this->view
->_build('field');
$fields = [];
// Only add the fields if they have a proper field and table alias.
foreach ($this->options['fields'] as $id) {
// Overridden fields can lead to fields missing from a display that are
// still set in the non-overridden combined filter.
if (!isset($this->view->field[$id])) {
// If fields are no longer available that are needed to filter by, make
// sure no results are shown to prevent displaying more then intended.
$this->view->build_info['fail'] = TRUE;
continue;
}
$field = $this->view->field[$id];
// Always add the table of the selected fields to be sure a table alias exists.
$field->ensureMyTable();
if (!empty($field->tableAlias) && !empty($field->realField)) {
$fields[] = "{$field->tableAlias}.{$field->realField}";
}
}
if ($fields) {
// We do not use the CONCAT_WS operator when there is only a single field.
// Using the CONCAT_WS operator with a single field is not a problem for
// the by core supported databases. Only the MS SQL Server requires the
// CONCAT_WS operator to be used with at least three arguments.
if (count($fields) == 1) {
$expression = reset($fields);
}
else {
// Multiple fields are separated by 3 spaces so that so that search
// strings that contain spaces are still only matched to single field
// values and not to multi-field values that exist only because we do
// the concatenation/LIKE trick.
$expression = implode(", ' ', ", $fields);
$expression = "CONCAT_WS(' ', {$expression})";
}
$info = $this->operators();
if (!empty($info[$this->operator]['method'])) {
$this->{$info[$this->operator]['method']}($expression);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.