public static function CompositeFormElementTrait::preRenderCompositeFormElement

public static CompositeFormElementTrait::preRenderCompositeFormElement($element)

Adds form element theming to an element if its title or description is set.

This is used as a pre render function for checkboxes and radios.

File

core/lib/Drupal/Core/Render/Element/CompositeFormElementTrait.php, line 18

Class

CompositeFormElementTrait
Provides a trait for radios, checkboxes, and similar composite form elements.

Namespace

Drupal\Core\Render\Element

Code

public static function preRenderCompositeFormElement($element) {
  // Set the element's title attribute to show #title as a tooltip, if needed.
  if (isset($element['#title']) && $element['#title_display'] == 'attribute') {
    $element['#attributes']['title'] = $element['#title'];
    if (!empty($element['#required'])) {
      // Append an indication that this field is required.
      $element['#attributes']['title'] .= ' (' . t('Required') . ')';
    }
  }

  if (isset($element['#title']) || isset($element['#description'])) {
    // @see #type 'fieldgroup'
    $element['#attributes']['id'] = $element['#id'] . '--wrapper';
    $element['#theme_wrappers'][] = 'fieldset';
    $element['#attributes']['class'][] = 'fieldgroup';
    $element['#attributes']['class'][] = 'form-composite';
  }
  return $element;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!Element!CompositeFormElementTrait.php/function/CompositeFormElementTrait::preRenderCompositeFormElement/8.1.x