In the node reference field module we needed the ability to alter the widget that cck adds to the form via js in content_add_more_js(). After a lot of messing around no solution was found.

I decided to copy the entire method and make the two necessary modifications.

Manually require cck code:

require_once drupal_get_path('module', 'content') . '/includes/content.node_form.inc';

Forcefully make alterations to the widget element.

$referenceable_fields = variable_get('nodereference_field_' . $field_name . '_fields', array());
nodereference_field_element_alter($form, $field, $referenceable_fields);

Change the code that selects the final element from the form to:

$field_form = (!empty($group_name)) ? $form[$group_name][$field_name . '_container'] : $form[$field_name . '_container'];

It would seem some sort of alter hook is in order.

Comments

markus_petrux’s picture

There's already a drupal_alter('form') in the AHAH handler for "Add more items" requests. You can implement your hook_form_alter() like this:

function myhook_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'content_add_more_js') {
  }
}

You should be able to figure out whether the request is for a field managed by your widget, and then alter the element to suit your needs.

boombatower’s picture

Project: Content Construction Kit (CCK) » Node reference field
Version: 6.x-2.x-dev » 6.x-1.x-dev
Component: General » Code

@markus_petrux: Thanks. I will attempt that and move issue back if it does not work. Interestedly enough I looked right at the line and missed the fact that it was doing that.