CCK fields and hook_form_alter()

If you ever tried to alter CCK fields with hook_form_alter() in the usual way, you probably had a rude awakening. The way CCK fields are generated is different from the way other form fields are. Especially the phase in which they are generated is different: The #process phase of CCK fields (that is the phase in which they are generated) takes place after the moment in which the $form array is built. 

Within the form API this phase is known as #after_build, an array of functions to be called after the $form array is built. It allows us to do something like:

/**
* Implementation of hook_form_alter().
*/
function example_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'example_node_form') {
    // Add an after_build function to process when everything's complete.
    $form['#after_build'][] = 'example_after_build';
  }
}

..and then:

function example_after_build($form, &$form_state) {
  // TODO: Stuff!
  return $form;
}

For details see: http://drupal.org/node/726282