0

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?

0

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().

| improve this answer | |
  • 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. – Lester Peabody Aug 27 '12 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 :) – Pontus Nilsson Aug 27 '12 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 ;) – Lester Peabody Aug 27 '12 at 14:31
  • Alright, updated :) – Pontus Nilsson Aug 27 '12 at 14:36
0

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.