function Combine::buildOptionsForm
Same name and namespace in other branches
- 9 core/modules/views/src/Plugin/views/filter/Combine.php \Drupal\views\Plugin\views\filter\Combine::buildOptionsForm()
- 8.9.x core/modules/views/src/Plugin/views/filter/Combine.php \Drupal\views\Plugin\views\filter\Combine::buildOptionsForm()
- 10 core/modules/views/src/Plugin/views/filter/Combine.php \Drupal\views\Plugin\views\filter\Combine::buildOptionsForm()
Provide the basic form which calls through to subforms.
If overridden, it is best to call through to the parent, or to at least make sure all of the functions in this form are called.
Parameters
array $form: An alterable, associative array containing the structure of the form, passed by reference.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FilterPluginBase::buildOptionsForm
File
-
core/
modules/ views/ src/ Plugin/ views/ filter/ Combine.php, line 34
Class
- Combine
- Filter handler which allows to search on multiple fields.
Namespace
Drupal\views\Plugin\views\filterCode
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$this->view
->initStyle();
// Allow to choose all fields as possible
if ($this->view->style_plugin
->usesFields()) {
$options = [];
foreach ($this->view->display_handler
->getHandlers('field') as $name => $field) {
// Only allow clickSortable fields. Fields without clickSorting will
// probably break in the Combine filter.
if ($field->clickSortable()) {
$options[$name] = $field->adminLabel(TRUE);
}
}
if ($options) {
$form['fields'] = [
'#type' => 'select',
'#title' => $this->t('Choose fields to combine for filtering'),
'#description' => $this->t("This filter doesn't work for very special field handlers."),
'#multiple' => TRUE,
'#options' => $options,
'#default_value' => $this->options['fields'],
];
}
else {
$form_state->setErrorByName('', $this->t('You have to add some fields to be able to use this filter.'));
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.