You are here

public function Combine::buildOptionsForm in Views (for Drupal 7) 8.3

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.

Overrides FilterPluginBase::buildOptionsForm

File

lib/Drupal/views/Plugin/views/filter/Combine.php, line 35
Definition of Drupal\views\Plugin\views\filter\Combine.

Class

Combine
Filter handler which allows to search on multiple fields.

Namespace

Drupal\views\Plugin\views\filter

Code

public function buildOptionsForm(&$form, &$form_state) {
  parent::buildOptionsForm($form, $form_state);
  $this->view
    ->initStyle();

  // Allow to choose all fields as possible
  if ($this->view->style_plugin
    ->usesFields()) {
    $options = array();
    foreach ($this->view->display_handler
      ->getHandlers('field') as $name => $field) {
      $options[$name] = $field
        ->adminLabel(TRUE);
    }
    if ($options) {
      $form['fields'] = array(
        '#type' => 'select',
        '#title' => t('Choose fields to combine for filtering'),
        '#description' => t("This filter doesn't work for very special field handlers."),
        '#multiple' => TRUE,
        '#options' => $options,
        '#default_value' => $this->options['fields'],
      );
    }
    else {
      form_set_error('', t('You have to add some fields to be able to use this filter.'));
    }
  }
}