I have a partially working solution for using hook_form after_build
on a CCK field. The field has various elements (it's created with a custom module but I don't want to modify that so I've created a small overrides module to do some trivial form alter stuff.) I've been at this a good part of the day and finally had some luck adding some simple text to the field so I am know I'm getting close.
In the main module, the CCK field has various elements. Once such element is:
$element['week_night'] = array(
'#type' => 'textfield',
'#title' => t('Week Night'),
'#default_value' => isset( $element['#value']['week_night'] ) ? $element['#value']['week_night'] : NULL,
'#attributes' => array( 'class' => 'rate-widget-rate-field' )
);
I am targeting the field itself in my overrides module as such:
<?php
function rates_override_form_alter(&$form, $form_state, $form_id) {
//drupal_set_message($form_id);
//dsm($form);
if($form_id == 'ldisilink_property_node_form'){
$form['#after_build'][] = '_rates_override_after_build';
}
}
function _rates_override_after_build($form, &$form_state) {
// This works so we know we are good to this point:
$form['field_rates']['#prefix'] = 'do stuff';
// Now we want to change the label on week_night but it's not working.
$week_night = $element['week_night'];
$form['field_rates'][$week_night]['#title'] = 'My new label title';
return $form;
}
What I am trying to do is alter the label for the element week_night
. Using dsm($form)
I've tried various combinations of:
$week_night = $element['week_night'];
$form['field_rates'][$week_night]['#title'] = 'My new label title';
... but it's not working yet, but I think I'm close.