I like simplifying the node form. One of my tricks in the past has been to conditionally hide CCK elements on new node creation when I want to enforce some kind of default. One of my favorite tricks is to whisk away things put in place by the Prepopulate module. Unfortunately for me, it's recent move to an #after_build
-based mechanism seems to be creating all kinds of collisions in how I can manipulate the widget.
This is what I used to do in hook_form_alter()
:
$form['field_my_nodereference_field'][0]['#type'] = 'hidden';
$form['field_my_nodereference_field'][0]['#value'] = $form['field_my_nodereference_field'][0]['#default_value']['nid'];
$form['field_my_nodereference_field'][0]['#parents'] = array('field_my_nodereference_field', 0, 'nid');
But when I try to play this game in #after_build
, I run into errors with the hidden
type's validation, or the nodereference_autocomplete_validation
. I have resorted to conditionally adding a CSS file. This makes me sad.