Pretty straight forward. For every label within a comment form, I wish to add a particular class to it. Using only functions in template.php, in Drupal 7, how can this be done? If it can't be done this way, what is the most straight-forward alternative?
2 Answers
Can't come up with a cleaner solution than implementing theme_form_element_label and adding the classes there depending on the elements name (comment_body) etc.
Maybe an option is to implement hook_form_comment_form_alter() and add specific identifiers to the elements you want to change the css class for the labels on in theme_form_element_label().
-
I did something similar already but it doesn't really do what I want it to do since it doesn't target the comment form specifically. I used the form element label preprocess function to add a theme suggestion based on the element id so I could individually target specific form labels, but that still doesn't get the granularity I want as far as targeting specific labels in a specific form... I don't think Drupal is actually capable of doing this, which blows my mind a bit. Commented Aug 27, 2012 at 13:09
-
Hmmm... maybe you could hook_form_comment_form_alter() first and add identifiers to the fields in the form there first and then more easily identify the elements in theme_form_element_label(). Not 100% still :) Commented Aug 27, 2012 at 14:22
-
I like where this is going... I won't be able to work on this until later this evening. If I get it working you should update your answer with the suggestion so I can give you 15 rep ;) Commented Aug 27, 2012 at 14:31
-
My solution a few years ago was to override comment-wrapper.tpl.php and comment.tpl.php in my sub-theme and I added my custom classes there, no need for functions or custom modules. You can find templates in comment core module.