You are here

public static function Dazzler::preprocessFormElement in Formdazzle! 2.x

Adds theme suggestions to a form_element's label.

Parameters

array $variables: The variables that will be passed to the form_element Twig template.

2 calls to Dazzler::preprocessFormElement()
DazzlerTest::testPreprocessFormElement in tests/src/Unit/DazzlerTest.php
@covers ::preprocessFormElement
formdazzle_preprocess_form_element in ./formdazzle.module
Implements hook_preprocess_HOOK().

File

src/Dazzler.php, line 364

Class

Dazzler
A class providing methods to modify Drupal form elements.

Namespace

Drupal\formdazzle

Code

public static function preprocessFormElement(array &$variables) {
  if (isset($variables['element']['#formdazzle'])) {
    $suggestion_suffix = $variables['element']['#formdazzle']['suggestion_suffix'];
    if (is_string($variables['label']['#theme'])) {
      $variables['label']['#theme'] .= $suggestion_suffix;
    }
    elseif (is_array($variables['label']['#theme'])) {
      $last_suggestion = array_key_last($variables['label']['#theme']);
      $variables['label']['#theme'][$last_suggestion] .= $suggestion_suffix;
    }
  }
}