function webform_preprocess_form_element in Webform 8.5
Same name and namespace in other branches
- 6.x includes/webform.theme.inc \webform_preprocess_form_element()
Implements hook_preprocess_form_element() for form element templates.
File
- includes/
webform.theme.inc, line 504 - Theme hooks, preprocessor, and suggestions.
Code
function webform_preprocess_form_element(&$variables) {
if (!WebformElementHelper::isWebformElement($variables['element'])) {
return;
}
// Setup description, help, and more.
_webform_preprocess_element($variables, [
'label',
'#title',
]);
// Make sure the #description_display is always applied to account for
// #more which is placed in the #description.
// @see template_preprocess_form_element()
if (isset($variables['description'])) {
$element =& $variables['element'];
$variables['description_display'] = $element['#description_display'];
}
// Add missing classes to the Claro theme's form elements.
// @see core/modules/system/templates/form-element.html.twig
// @see claro/templates/form-element.html.twig
// @todo Once Claro is stable determine if this code should removed.
static $is_claro_theme;
if (!isset($is_claro_theme)) {
/** @var \Drupal\webform\WebformThemeManagerInterface $theme_manager */
$theme_manager = \Drupal::service('webform.theme_manager');
$is_claro_theme = $theme_manager
->isActiveTheme('claro');
}
if ($is_claro_theme) {
// Add system .form-type-TYPE class.
if (!empty($variables['type'])) {
$variables['attributes']['class'][] = 'form-type-' . Html::getClass($variables['type']);
}
// Add system .description class.
if (isset($variables['description'])) {
if (empty($variables['description']['attributes'])) {
$variables['description']['attributes'] = new Attribute();
}
$variables['description']['attributes']
->addClass('description');
}
}
}