How can I theme a form "checkboxes" element? I've got a checkboxes field displayed on the user profile form. I'm trying to restyle that field to put the description BEFORE the checkboxes. That seems like it should be a simple thing?

So far I've got:

function MYTHEME_form_user_profile_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    $form['my_field_id'][LANGUAGE_NONE]['#theme'] = 'checkboxes_description_before_element';
}

function MYTHEME_theme($existing, $type, $theme, $path) {
    return array(
        'checkboxes_description_before_element' =&gt; array(
            'render element' =&gt; 'element',
            'function' =&gt; 'theme_checkboxes_description_before_element'
        ),
    );
}

function MYTHEME_checkboxes_description_before_element($variables) {
    return "XYZ";
}


The checkboxes field is still stubbornly sitting on the markup generated by theme_checkboxes instead of "XYZ".

I know that the form element is getting the new '#theme' through checking with dpm().
The checkboxes description is not rendered in theme_checkboxes or theme_checkbox. It comes from theme_form_element.


If you want every form element on the site (not just checkboxes) to have the description first, then you could just override and modify theme_form_element.
If you want only specific checkboxes to have this, then you could override and modify theme_form_element to position the description based on a variable (similar to what it already does with #title_display). You could then set the variable when creating the FAPI array.
If you want all checkboxes (but only checkboxes) to follow this behaviour, then you could override theme_form_element as above, and use hook_element_info_alter() and change checkboxes to have the new variable you created appopriately set.


Let me know if you have any questions.