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.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | noderefcreate_access_field_properly_in_validate-1217150-1.patch | 746 bytes | dtarc |
Comments
Comment #1
dtarc commentedPatch is for 7.x-dev.
Comment #2
dtarc commentedUpdated the title to better reflect the issue.
Comment #3
jackbravo commentedThanks a lot, I tested this and it works just fine.
Committed.
Comment #5
socialnicheguru commentedI 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)