I need to hide the text format tips for body field, depending on user role, in a module. After some research, I found this kind of code:
function mymodule_form_node_form_alter(&$form, &$form_state) {
if (isset($form['body'][LANGUAGE_NONE][0]['#after_build'])) {
$form['body'][LANGUAGE_NONE][0]['#after_build'][] = 'mymodule_node_after_build';
} else {
$form['body'][LANGUAGE_NONE][0]['#after_build'] = array('mymodule_node_after_build');
}
}
function mymodule_node_after_build(&$form, &$form_state) {
/*if (!user_access('administer filters')) {
$form['LANGUAGE_NONE']['0']['format']['#attributes']['class'][] = 'invisible';
}*/
}
*I know the mymodule_node_after_build function is all commented, so
it's doing nothing, but it's here only for illustration. Just adding
#after_build
to the form or field makes it all invisible - and this is the issue here.*
The above code results in field body not displayed at all, instead of just hiding text format info. More precisely, the html contains this code in place of the body field (just an empty div):
<div class="field-type-text-with-summary field-name-body field-widget-text-textarea-with-summary form-wrapper" id="edit-body"></div>
I tried setting this also for:
$form['body'][LANGUAGE_NONE]['#after_build']
$form['body']['#after_build']
$form['#after_build']
(the last one displays white space instead of the whole form)
Unless there is another much simpler solution to this problem, I'd like to use the above approach or something similar in a module, but it's not working!! So what's wrong with it?