function RenderElement::setAttributes
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Render/Element/RenderElement.php \Drupal\Core\Render\Element\RenderElement::setAttributes()
- 10 core/lib/Drupal/Core/Render/Element/RenderElement.php \Drupal\Core\Render\Element\RenderElement::setAttributes()
- 8.9.x core/lib/Drupal/Core/Render/Element/RenderElement.php \Drupal\Core\Render\Element\RenderElement::setAttributes()
7 calls to RenderElement::setAttributes()
- Date::preRenderDate in core/
lib/ Drupal/ Core/ Render/ Element/ Date.php - Adds form-specific attributes to a 'date' #type element.
- media_preprocess_media_reference_help in core/
modules/ media/ media.module - Implements hook_preprocess_HOOK() for media reference widgets.
- Password::preRenderPassword in core/
lib/ Drupal/ Core/ Render/ Element/ Password.php - Prepares a #type 'password' render element for input.html.twig.
- template_preprocess_fieldset in core/
includes/ form.inc - Prepares variables for fieldset element templates.
- template_preprocess_select in core/
includes/ form.inc - Prepares variables for select element templates.
File
-
core/
lib/ Drupal/ Core/ Render/ Element/ RenderElement.php, line 132
Class
- RenderElement
- Provides a base class for render element plugins.
Namespace
Drupal\Core\Render\ElementCode
public static function setAttributes(&$element, $class = []) {
if (!empty($class)) {
if (!isset($element['#attributes']['class'])) {
$element['#attributes']['class'] = [];
}
$element['#attributes']['class'] = array_merge($element['#attributes']['class'], $class);
}
// This function is invoked from form element theme functions, but the
// rendered form element may not necessarily have been processed by
// \Drupal::formBuilder()->doBuildForm().
if (!empty($element['#required'])) {
$element['#attributes']['class'][] = 'required';
$element['#attributes']['required'] = 'required';
$element['#attributes']['aria-required'] = 'true';
}
if (isset($element['#parents']) && isset($element['#errors']) && !empty($element['#validated'])) {
$element['#attributes']['class'][] = 'error';
$element['#attributes']['aria-invalid'] = 'true';
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.