Posted by Letharion on December 2, 2009 at 6:41pm
To be able to control the form of a custom node, I have created it in a module.
In hook_form_FORM_ID_alter I have
unset($form_id['revision_information']);
unset($form_id['author']);
unset($form_id['body_filter']);
unset($form_id['options']);which strips most of the things I want, however for some reason this:
unset($form_id['menu']);
unset($form_id['comment_settings']);
$form_id['attachments']['#collapsed'] = FALSE;
$form_id['attachments']['#description'] = t('Insert text here');Doesn't work unless I place it in hook_form_alter.
I'm trying to understand why that is, and also, why placing the latter code in alter_form doesn't affect other node types?
Comments
...
Probably because your module's hook_form_alter is execute before the menu module's hook_form_alter. So the menu module overwrites your alterations. Modules have "weights" and one solution is to make yours heavier so its hooks execute after certain others'.
(Not that these fields are only displayed for priviledged users, so if your purpose is to "clean up" the interface, this may not be needed --because "normal" users don't see these fields.)
(On the extreme side, there's a way to have "mini forms". BTW, the code in my comment on that page doesn't suffer form the "weight" problem.)
You should name that variable $form. Not $form_id.
unset()ing fields probably isn't a very robust thing to do, because the submitting handler may still expect to see this data. (Though the node form is more lenient.)
So do
$form[ELEMENT_NAME]['#access'] = FALSE;instead. (When done to a fieldset it's as if done to all the elements below.)