diff --git a/core/includes/form.inc b/core/includes/form.inc index 838a156..9b9283b 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -361,35 +361,32 @@ function form_get_options($element, $key) { function template_preprocess_fieldset(&$variables) { $element = $variables['element']; Element::setAttributes($element, array('id')); - Element\RenderElement::setAttributes($element, array('form-wrapper')); $variables['attributes'] = $element['#attributes']; - $variables['attributes']['class'][] = 'form-item'; $variables['prefix'] = isset($element['#field_prefix']) ? $element['#field_prefix'] : NULL; $variables['suffix'] = isset($element['#field_suffix']) ? $element['#field_suffix'] : NULL; + $variables['title_display'] = isset($element['#title_display']) ? $element['#title_display'] : NULL; $variables['children'] = $element['#children']; - $legend_attributes = array(); - if (isset($element['#title_display']) && $element['#title_display'] == 'invisible') { - $legend_attributes['class'][] = 'visually-hidden'; - } - $variables['legend']['attributes'] = new Attribute($legend_attributes); + $variables['required'] = !empty($element['#required']) ? $element['#required'] : NULL; + $variables['legend']['title'] = (isset($element['#title']) && $element['#title'] !== '') ? Xss::filterAdmin($element['#title']) : ''; - $legend_span_attributes = array('class' => array('fieldset-legend')); - if (!empty($element['#required'])) { - $legend_span_attributes['class'][] = 'form-required'; - $variables['legend_span']['attributes'] = new Attribute($legend_span_attributes); - } + $variables['legend']['attributes'] = new Attribute(); + + $variables['legend_span']['attributes'] = new Attribute(); + if (!empty($element['#description'])) { $description_id = $element['#attributes']['id'] . '--description'; - $description_attributes = array( - 'class' => 'description', - 'id' => $description_id, - ); + $description_attributes['id'] = $description_id; $variables['description']['attributes'] = new Attribute($description_attributes); $variables['description']['content'] = $element['#description']; // Add the description's id to the fieldset aria attributes. $variables['attributes']['aria-describedby'] = $description_id; } + + // Pass element's #type to template. + if (!empty($element['#type'])) { + $variables['type'] = $element['#type']; + } } /** @@ -438,10 +435,6 @@ function template_preprocess_radios(&$variables) { if (isset($element['#id'])) { $variables['attributes']['id'] = $element['#id']; } - $variables['attributes']['class'][] = 'form-radios'; - if (!empty($element['#attributes']['class'])) { - $variables['attributes']['class'] = array_merge($variables['attributes']['class'], $element['#attributes']['class']); - } if (isset($element['#attributes']['title'])) { $variables['attributes']['title'] = $element['#attributes']['title']; } @@ -464,11 +457,6 @@ function template_preprocess_checkboxes(&$variables) { if (isset($element['#id'])) { $variables['attributes']['id'] = $element['#id']; } - $variables['attributes']['class'] = array(); - $variables['attributes']['class'][] = 'form-checkboxes'; - if (!empty($element['#attributes']['class'])) { - $variables['attributes']['class'] = array_merge($variables['attributes']['class'], $element['#attributes']['class']); - } if (isset($element['#attributes']['title'])) { $variables['attributes']['title'] = $element['#attributes']['title']; } @@ -545,18 +533,11 @@ function template_preprocess_textarea(&$variables) { $element = $variables['element']; Element::setAttributes($element, array('id', 'name', 'rows', 'cols', 'placeholder')); Element\RenderElement::setAttributes($element, array('form-textarea')); - $variables['wrapper_attributes'] = new Attribute(array( - 'class' => array('form-textarea-wrapper'), - )); - - // Add resizable behavior. - if (!empty($element['#resizable'])) { - $element['#attributes']['class'][] = 'resize-' . $element['#resizable']; - } - + $variables['wrapper_attributes'] = new Attribute(); $variables['attributes'] = new Attribute($element['#attributes']); - $variables['value'] = String::checkPlain($element['#value']); + $variables['resizable'] = !empty($element['#resizable']) ? $element['#resizable'] : NULL; + $variables['required'] = !empty($element['#required']) ? $element['#required'] : NULL; } /** @@ -629,27 +610,23 @@ function template_preprocess_form_element(&$variables) { $variables['attributes']['id'] = $element['#id']; } - // Add element's #type and #name as class to aid with JS/CSS selectors. - $variables['attributes']['class'][] = 'form-item'; + // Pass element's #type and #name to template. if (!empty($element['#type'])) { - $variables['attributes']['class'][] = 'form-type-' . strtr($element['#type'], '_', '-'); + $variables['type'] = $element['#type']; } if (!empty($element['#name'])) { - $variables['attributes']['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => '')); - } - // Add a class for disabled elements to facilitate cross-browser styling. - if (!empty($element['#attributes']['disabled'])) { - $variables['attributes']['class'][] = 'form-disabled'; + $variables['name'] = $element['#name']; } + // Pass element's disabled status to template. + $variables['disabled'] = !empty($element['#attributes']['disabled']) ? $element['#attributes']['disabled'] : NULL; + // If #title is not set, we don't display any label. if (!isset($element['#title'])) { $element['#title_display'] = 'none'; } - // If #title_dislay is not some of the visible options, add a CSS class. - if ($element['#title_display'] != 'before' && $element['#title_display'] != 'after') { - $variables['attributes']['class'][] = 'form-no-label'; - } + + $variables['title_display'] = $element['#title_display']; $variables['prefix'] = isset($element['#field_prefix']) ? $element['#field_prefix'] : NULL; $variables['suffix'] = isset($element['#field_suffix']) ? $element['#field_suffix'] : NULL; @@ -657,10 +634,7 @@ function template_preprocess_form_element(&$variables) { $variables['description'] = NULL; if (!empty($element['#description'])) { $variables['description_display'] = $element['#description_display']; - $description_attributes = array('class' => array('description')); - if ($element['#description_display'] === 'invisible') { - $description_attributes['class'][] = 'visually-hidden'; - } + $description_attributes = []; if (!empty($element['#id'])) { $description_attributes['id'] = $element['#id'] . '--description'; } @@ -702,14 +676,9 @@ function template_preprocess_form_element_label(&$variables) { // If title and required marker are both empty, output no label. $variables['title'] = (isset($element['#title']) && $element['#title'] !== '') ? Xss::filterAdmin($element['#title']) : ''; $variables['attributes'] = array(); - // Style the label as class option to display inline with the element. - if ($element['#title_display'] == 'after') { - $variables['attributes']['class'][] = 'option'; - } - // Show label only to screen readers to avoid disruption in visual flows. - elseif ($element['#title_display'] == 'invisible') { - $variables['attributes']['class'][] = 'visually-hidden'; - } + + // Pass element's title_display to template. + $variables['title_display'] = $element['#title_display']; // A #for property of a dedicated #type 'label' element as precedence. if (!empty($element['#for'])) { @@ -725,13 +694,8 @@ function template_preprocess_form_element_label(&$variables) { $variables['attributes']['for'] = $element['#id']; } - // For required elements a 'form-required' class is appended to the - // label attributes. - $variables['required'] = FALSE; - if (!empty($element['#required'])) { - $variables['required'] = TRUE; - $variables['attributes']['class'][] = 'form-required'; - } + // Pass element's required to template. + $variables['required'] = !empty($element['#required']) ? TRUE : NULL; } /** diff --git a/core/lib/Drupal/Core/Render/Element/CompositeFormElementTrait.php b/core/lib/Drupal/Core/Render/Element/CompositeFormElementTrait.php index 4c1855a..92de0c8 100644 --- a/core/lib/Drupal/Core/Render/Element/CompositeFormElementTrait.php +++ b/core/lib/Drupal/Core/Render/Element/CompositeFormElementTrait.php @@ -33,8 +33,6 @@ public static function preRenderCompositeFormElement($element) { if (isset($element['#title']) || isset($element['#description'])) { // @see #type 'fieldgroup' $element['#theme_wrappers'][] = 'fieldset'; - $element['#attributes']['class'][] = 'fieldgroup'; - $element['#attributes']['class'][] = 'form-composite'; } return $element; } diff --git a/core/modules/system/templates/checkboxes.html.twig b/core/modules/system/templates/checkboxes.html.twig index 00384d3..7c56355 100644 --- a/core/modules/system/templates/checkboxes.html.twig +++ b/core/modules/system/templates/checkboxes.html.twig @@ -14,4 +14,4 @@ @todo: remove this file once http://drupal.org/node/1819284 is resolved. This is identical to core/modules/system/templates/container.html.twig #} -