function OliveroHooks::preprocessFormElement

Same name and namespace in other branches
  1. 11.x core/themes/olivero/src/Hook/OliveroHooks.php \Drupal\olivero\Hook\OliveroHooks::preprocessFormElement()

Implements hook_preprocess_HOOK() for form-element.

Attributes

#[Hook('preprocess_form_element')]

File

core/themes/olivero/src/Hook/OliveroHooks.php, line 222

Class

OliveroHooks
Hook implementations for olivero.

Namespace

Drupal\olivero\Hook

Code

public function preprocessFormElement(&$variables) : void {
  if (in_array($variables['element']['#type'] ?? FALSE, [
    'checkbox',
    'radio',
  ], TRUE)) {
    $variables['attributes']['class'][] = 'form-type-boolean';
  }
  if (!empty($variables['description']['attributes'])) {
    $variables['description']['attributes']->addClass('form-item__description');
  }
  if ($variables['disabled']) {
    $variables['label']['#attributes']['class'][] = 'is-disabled';
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.