function template_preprocess_views_exposed_form

Prepares variables for views exposed form templates.

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

Parameters

array $vars: An associative array containing:

  • form: A render element representing the form.

File

drupal/core/modules/views/views.theme.inc, line 1054
Preprocessors and helper functions to make theming easier.

Code

function template_preprocess_views_exposed_form(&$vars) {
  $form =& $vars['form'];

  // Put all single checkboxes together in the last spot.
  $checkboxes = array();
  if (!empty($form['q'])) {
    $vars['q'] = $form['q'];
  }
  $vars['widgets'] = array();
  foreach ($form['#info'] as $id => $info) {

    // Set aside checkboxes.
    if (isset($form[$info['value']]['#type']) && $form[$info['value']]['#type'] == 'checkbox') {
      $checkboxes[] = $form[$info['value']];
      continue;
    }
    $widget = new stdClass();

    // set up defaults so that there's always something there.
    $widget->label = $widget->operator = $widget->widget = $widget->description = '';
    $widget->id = isset($form[$info['value']]['#id']) ? $form[$info['value']]['#id'] : '';
    if (!empty($info['label'])) {
      $widget->label = check_plain($info['label']);
    }
    if (!empty($info['operator']) && isset($form[$info['operator']])) {
      $widget->operator = $form[$info['operator']];
    }
    $widget->widget = $form[$info['value']];
    if (!empty($info['description'])) {
      $widget->description = check_plain($info['description']);
    }
    $vars['widgets'][$id] = $widget;

    // Unset the widget, so that it doesn't get rendered twice.
    unset($form[$info['value']]);
  }

  // Wrap up all the checkboxes we set aside into a widget.
  if (!empty($checkboxes)) {
    $widget = new stdClass();

    // set up defaults so that there's always something there.
    $widget->label = $widget->operator = $widget->widget = NULL;
    $widget->id = 'checkboxes';
    $widget->widget = $checkboxes;
    $vars['widgets']['checkboxes'] = $widget;
  }
}