Updated: Comment #71
Problem/Motivation
The way a form element label is rendered is:
return '' . $t('!title !required', array('!title' => $title, '!required' => $required)) . "\n";
where $attributes['class'] is either option
or element-invisible
. theme_form_element_label() completely ignores any attributes passed in $variables['element']['#attributes']
. This makes adding classes to a form label impossible for example.
To reproduce, add this to your theme:
function mytheme_preprocess_form_element_label(&$vars) {
$vars['element']['#attributes']['class'][] = 'mycustomclass';
}
and note that the label element will not have that class.
Proposed resolution
Rewrite theme_form_element_label() in such a way that it does not ignore the attributes passed in $variables['element']['#attributes']
Remaining tasks
The patch has been re-rolled, applied and tested. It passes all system tests. There is a concern about two spots where line breaks have been inserted (to wrap within 80 columns) -> evidently this is not necessary to conform to coding standards and apparently causes it to not conform to coding standards. There are two larger concerns about the approach of the patch itself: one part (change to theme_radios) is supposed to be broken out into a separate issue; adding title_classes_array is not desired.
User interface changes
None.
API changes
Yes.
Original report by scor
The way a form element label is rendered is:
return '' . $t('!title !required', array('!title' => $title, '!required' => $required)) . "\n";
where $attributes['class'] is either option
or element-invisible
. theme_form_element_label() completely ignores any attributes passed in $variables['element']['#attributes']
. This makes adding classes to a form label impossible for example.
To reproduce, add this to your theme:
function mytheme_preprocess_form_element_label(&$vars) {
$vars['element']['#attributes']['class'][] = 'mycustomclass';
}
and note that the label element will not have that class.
Other form elements such as theme_textfield() do respect the passed in #attributes values.
2013-06-04: The patch has been re-rolled, applied and tested. It passes all system tests. There is a concern about two spots where line breaks have been inserted (to wrap within 80 columns) -> evidently this is not necessary to conform to coding standards and apparently causes it to not conform to coding standards. There are two larger concerns about the approach of the patch itself: one part (change to theme_radios) is supposed to be broken out into a separate issue; adding title_classes_array is not desired.