You are here

public function FormElement::preprocessElement in Open Social 8.9

Same name and namespace in other branches
  1. 8 themes/socialbase/src/Plugin/Preprocess/FormElement.php \Drupal\socialbase\Plugin\Preprocess\FormElement::preprocessElement()
  2. 8.2 themes/socialbase/src/Plugin/Preprocess/FormElement.php \Drupal\socialbase\Plugin\Preprocess\FormElement::preprocessElement()
  3. 8.3 themes/socialbase/src/Plugin/Preprocess/FormElement.php \Drupal\socialbase\Plugin\Preprocess\FormElement::preprocessElement()
  4. 8.4 themes/socialbase/src/Plugin/Preprocess/FormElement.php \Drupal\socialbase\Plugin\Preprocess\FormElement::preprocessElement()
  5. 8.5 themes/socialbase/src/Plugin/Preprocess/FormElement.php \Drupal\socialbase\Plugin\Preprocess\FormElement::preprocessElement()
  6. 8.6 themes/socialbase/src/Plugin/Preprocess/FormElement.php \Drupal\socialbase\Plugin\Preprocess\FormElement::preprocessElement()
  7. 8.7 themes/socialbase/src/Plugin/Preprocess/FormElement.php \Drupal\socialbase\Plugin\Preprocess\FormElement::preprocessElement()
  8. 8.8 themes/socialbase/src/Plugin/Preprocess/FormElement.php \Drupal\socialbase\Plugin\Preprocess\FormElement::preprocessElement()

Preprocess the variables array if an element is present.

Parameters

\Drupal\bootstrap\Utility\Element $element: The Element object.

\Drupal\bootstrap\Utility\Variables $variables: The Variables object.

Overrides FormElement::preprocessElement

File

themes/socialbase/src/Plugin/Preprocess/FormElement.php, line 21

Class

FormElement
Pre-processes variables for the "form_element" theme hook.

Namespace

Drupal\socialbase\Plugin\Preprocess

Code

public function preprocessElement(Element $element, Variables $variables) {

  // Check if form element is part of
  // email_notifications and add class to label.
  if ($element
    ->hasProperty('parents') && in_array('email_notifications', $element
    ->getProperty('parents'))) {
    $variables['label']['#attributes']['class'][] = 'control-label--wide';
  }

  // Tell the label it is in a switch form element.
  if (!empty($variables['element']['#attributes']['data-switch'])) {
    $variables['label']['#switch'] = TRUE;
  }

  // Use cards for the vertical tabs component.
  if ($variables['element']['#type'] === 'vertical_tabs') {
    $variables['attributes']['class'][] = 'card';
  }
  parent::preprocessElement($element, $variables);
}