On my Drupal website I’ve got something like this:
<div class="form-item form-type-textfield item-1">
<div class="form-item form-type-textfield item-2">
<div class="form-item form-type-textfield item-3">
<div class="form-item form-type-textfield item-4">
...
Is there any way to get it like this
<div class="form-item form-type-textfield item-1 added-class">
or
<div class="wrapped-class">
<div class="form-item form-type-textfield item-1">
</div>
So, to add a class to an item or wrap one around it. I played around with the hook_preprocess, but that didn’t work out.
A hook_form_alter isn’t the solution either, since you have to do it for each form… The div-class appears on multiple pages, so I would like to catch the statement with one code-snippet.
Any ideas?
I’m surprised Drupal hasn’t ‘farmed out’ this functionality but if you look at the
theme_form_element()function you can see the classes are statically set.The only way I can think to do what you want in code is to use a theme override for that function:
In that function you’ll need to place the entire code from the
theme_form_elementfunction (seems like overkill I know but I can’t think of a better way), and add your new class to the$attributes['class']array: