You are here

function claro_preprocess_views_exposed_form in Drupal 8

Same name and namespace in other branches
  1. 9 core/themes/claro/claro.theme \claro_preprocess_views_exposed_form()
  2. 10 core/themes/claro/claro.theme \claro_preprocess_views_exposed_form()

Implements hook_preprocess_HOOK for views_exposed_form.

File

core/themes/claro/claro.theme, line 612
Functions to support theming in the Claro theme.

Code

function claro_preprocess_views_exposed_form(&$variables) {
  $form =& $variables['form'];

  // Add BEM classes for items in the form.
  // Sorted keys.
  $child_keys = Element::children($form, TRUE);
  $last_key = NULL;
  $child_before_actions_key = NULL;
  foreach ($child_keys as $child_key) {
    if (!empty($form[$child_key]['#type'])) {
      if ($form[$child_key]['#type'] === 'actions') {

        // We need the key of the element that precedes the actions element.
        $child_before_actions_key = $last_key;
        $form[$child_key]['#attributes']['class'][] = 'views-exposed-form__item';
        $form[$child_key]['#attributes']['class'][] = 'views-exposed-form__item--actions';
      }
      if (!in_array($form[$child_key]['#type'], [
        'hidden',
        'actions',
      ])) {
        $form[$child_key]['#wrapper_attributes']['class'][] = 'views-exposed-form__item';
        $last_key = $child_key;
      }
    }
  }
  if ($child_before_actions_key) {

    // Add a modifier class to the item that precedes the form actions.
    $form[$child_before_actions_key]['#wrapper_attributes']['class'][] = 'views-exposed-form__item--preceding-actions';
  }
}