Skip to content
Snippets Groups Projects
Commit c65b73dd authored by shadcn's avatar shadcn
Browse files

Fix template for checkboxes and radios

parent 3fe8ad5a
No related branches found
Tags 8.x-2.0
No related merge requests found
......@@ -25,3 +25,14 @@ function radix_preprocess_input(&$variables) {
// Add the element type to the theme.
$variables['type'] = $element['#type'];
}
/**
* Implements template_preprocess_form_element().
*/
function radix_preprocess_form_element(&$variables) {
// Render the form element inside the label for checkbox and radio.
if (in_array($variables['element']['#type'], ['checkbox', 'radio'])) {
$variables['label']['#children'] = $variables['children'];
unset($variables['children']);
}
}
{#
/**
* @file
* Default theme implementation for a form element label.
*
* Available variables:
* - element: an input element.
* - title: The label's text.
* - title_display: Elements title_display setting.
* - description: element description.
* - required: An indicator for whether the associated form element is required.
* - attributes: A list of HTML attributes for the label.
*
* @see template_preprocess_form_element_label()
*
* @ingroup templates
*/
#}
{%-
set classes = [
title_display == 'after' ? 'option',
title_display == 'invisible' ? 'visually-hidden',
required ? 'js-form-required',
required ? 'form-required',
]
-%}
{%- if title is not empty or required -%}
<label{{ attributes.addClass(classes) }}> {{ element }} {{ title }}
{%- if description -%}
<p class="help-block">{{ description }}</p>
{%- endif -%}
</label>
{%- if required and title_display == 'before' -%}
<span class="form-required">*</span>
{%- endif -%}
{%- endif -%}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment