Skip to content
Snippets Groups Projects
Commit 622a3549 authored by catch's avatar catch
Browse files

Issue #2774255 by joelpittet, lauriii: Allow form element to set attributes for label

parent 3ec70e5b
No related branches found
No related tags found
No related merge requests found
......@@ -432,6 +432,7 @@ function template_preprocess_form_element(&$variables) {
$element += array(
'#title_display' => 'before',
'#wrapper_attributes' => array(),
'#label_attributes' => array(),
);
$variables['attributes'] = $element['#wrapper_attributes'];
......@@ -479,6 +480,7 @@ function template_preprocess_form_element(&$variables) {
$variables['label_display'] = $element['#title_display'];
$variables['label'] = array('#theme' => 'form_element_label');
$variables['label'] += array_intersect_key($element, array_flip(array('#id', '#required', '#title', '#title_display')));
$variables['label']['#attributes'] = $element['#label_attributes'];
$variables['children'] = $element['#children'];
}
......
......@@ -31,6 +31,16 @@ public function testAttributes() {
$this->render($render_array);
$elements = $this->xpath($css_selector_converter->toXPath('.kitten'));
$this->assertCount(1, $elements);
// Add label attributes to a form element.
$render_array = [
'#type' => 'textfield',
'#label_attributes' => ['class' => ['meow']],
'#title' => 'Kitten sounds',
];
$this->render($render_array);
$elements = $this->xpath($css_selector_converter->toXPath('label.meow'));
$this->assertCount(1, $elements);
}
}
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