You are here

public function Links::exposedFormAlter in Better Exposed Filters 8.5

Same name in this branch
  1. 8.5 src/Plugin/better_exposed_filters/filter/Links.php \Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter\Links::exposedFormAlter()
  2. 8.5 src/Plugin/better_exposed_filters/sort/Links.php \Drupal\better_exposed_filters\Plugin\better_exposed_filters\sort\Links::exposedFormAlter()
  3. 8.5 src/Plugin/better_exposed_filters/pager/Links.php \Drupal\better_exposed_filters\Plugin\better_exposed_filters\pager\Links::exposedFormAlter()
Same name and namespace in other branches
  1. 8.4 src/Plugin/better_exposed_filters/filter/Links.php \Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter\Links::exposedFormAlter()

Manipulate views exposed from element.

Parameters

array $form: The views configuration form.

\Drupal\Core\Form\FormStateInterface $form_state: Form state.

Overrides FilterWidgetBase::exposedFormAlter

File

src/Plugin/better_exposed_filters/filter/Links.php, line 51

Class

Links
Default widget implementation.

Namespace

Drupal\better_exposed_filters\Plugin\better_exposed_filters\filter

Code

public function exposedFormAlter(array &$form, FormStateInterface $form_state) {

  /** @var \Drupal\views\Plugin\views\filter\FilterPluginBase $filter */
  $filter = $this->handler;
  $field_id = $this
    ->getExposedFilterFieldId();
  parent::exposedFormAlter($form, $form_state);
  if (!empty($form[$field_id])) {

    // Clean up filters that pass objects as options instead of strings.
    if (!empty($form[$field_id]['#options'])) {
      $form[$field_id]['#options'] = BetterExposedFiltersHelper::flattenOptions($form[$field_id]['#options']);
    }

    // Support rendering hierarchical links (e.g. taxonomy terms).
    if (!empty($filter->options['hierarchy'])) {
      $form[$field_id]['#bef_nested'] = TRUE;
    }
    $form[$field_id]['#theme'] = 'bef_links';

    // Exposed form displayed as blocks can appear on pages other than
    // the view results appear on. This can cause problems with
    // select_as_links options as they will use the wrong path. We
    // provide a hint for theme functions to correct this.
    $form[$field_id]['#bef_path'] = $this
      ->getExposedFormActionUrl($form_state);
  }
}