function PreprocessHooks::viewsExposedForm
Same name and namespace in other branches
- 11.x core/themes/admin/src/Hook/PreprocessHooks.php \Drupal\admin\Hook\PreprocessHooks::viewsExposedForm()
Implements hook_preprocess_HOOK() for views_exposed_form.
Attributes
#[Hook('preprocess_views_exposed_form')]
File
-
core/
themes/ admin/ src/ Hook/ PreprocessHooks.php, line 1346
Class
- PreprocessHooks
- Provides preprocess implementations.
Namespace
Drupal\admin\HookCode
public function viewsExposedForm(array &$variables) : void {
$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';
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.