For those not familiar with it, Field Collection (http://drupal.org/project/field_collection) is the D7 module handling CCK Multigroup.

I ran into an issue today trying to use Node Reference Create as the widget on a field within a Field Collection. Node Reference Create needs the field in noderefcreate_autocomplete_validate() and tries to grab it from $form_state['fields'][$element['#field_name']]. Unfortunately Field Collection isn't putting the field there.

Node Reference Create should be using core Fields UI functions to get information about the field from the $form_state array. It should not try to access the field in the likeliest place in $form_state--because it might not be there.

So the two lines at the start of noderefcreate_autocomplete_validate():

function noderefcreate_autocomplete_validate($element, &$form_state, $form) {
  $field = $form_state['field'][$element['#field_name']][$element['#language']]['field'];
  $instance = $form_state['field'][$element['#field_name']][$element['#language']]['instance'];

should be:

function noderefcreate_autocomplete_validate($element, &$form_state, $form) {
  $field = field_widget_field($element, $form_state);
  $instance = field_widget_instance($element, $form_state);

Making this change solved the incompatibility with Field Collection. I'll upload a patch in the comments.

Comments

dtarc’s picture

Title: Incomptible with Field Collection » Incompatible with Field Collection
Status: Active » Needs review
StatusFileSize
new746 bytes

Patch is for 7.x-dev.

dtarc’s picture

Title: Incompatible with Field Collection » Use core functions to access field in widget validate
Assigned: dtarc » Unassigned

Updated the title to better reflect the issue.

jackbravo’s picture

Status: Needs review » Fixed

Thanks a lot, I tested this and it works just fine.

Committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

socialnicheguru’s picture

Version: 7.x-1.0-beta3 » 7.x-1.0

I tried applying to 1.0 version since dev is not up yet and got an error

git apply n*patch
fatal: git diff header lacks filename information when removing 1 leading pathname components (line 5)