You are here

function better_exposed_filters_preprocess_views_exposed_form in Better Exposed Filters 8.5

Same name and namespace in other branches
  1. 8.3 better_exposed_filters.module \better_exposed_filters_preprocess_views_exposed_form()
  2. 8.4 includes/better_exposed_filters.theme.inc \better_exposed_filters_preprocess_views_exposed_form()

Prepares variables for views exposed form templates.

Default template: views-exposed-form.html.twig.

Parameters

array $variables: An associative array containing:

  • form: A render element representing the form.

File

includes/better_exposed_filters.theme.inc, line 62
Theme hooks, preprocessor, and suggestions.

Code

function better_exposed_filters_preprocess_views_exposed_form(array &$variables) {

  // Checks if Token module is enabled.
  if (!\Drupal::moduleHandler()
    ->moduleExists('token')) {
    return;
  }

  // Replaces tokens in description field of the exposed filter.
  foreach ($variables['form']['#info'] as $name => &$info) {
    if (isset($info['description']) && isset($variables['form'][explode('filter-', $name)[1]]['#description'])) {
      $info['description'] = \Drupal::service('token')
        ->replace($info['description']);
      $variables['form'][explode('filter-', $name)[1]]['#description'] = $info['description'];
    }
  }
}