When editing an empty entityreference field as autocomplete:

Warning: Invalid argument supplied for foreach() in entityreference_field_widget_form()
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

geek-merlin’s picture

Issue summary: View changes

correction

geek-merlin’s picture

Status: Active » Needs review
FileSize
798 bytes

we need a simple patch like this to prevent foreach eating NULL values.

pyrello’s picture

Patch from #1 appears to work.

amitaibu’s picture

Status: Needs review » Closed (cannot reproduce)

Sorry for the late reply... :)
Seems to be already resolved.

davidi’s picture

Is there a reason this patch was never applied. I am migrating one of our drupal sites and noticed that a developer had this patch code in our entityreference.module. Looking in the source repository, I don't see the fix merged in anywhere. Is it necessary? If so can the patch be applied in the next release?
Thanks

jrbeeman’s picture

Title: "Invalid argument supplied for foreach" » Invalid argument supplied for foreach in entityreference_field_widget_form()
Status: Closed (cannot reproduce) » Needs review
FileSize
599 bytes

Re-opening as we ran into this issue during a Commons sprint. Commons uses a combination of OG, Entity Reference Prepopulate, and Entity Reference. In cases where a prepopulate argument isn't passed in the URL, we receive this warning. I believe the fix is simple: Don't assume $items has a value. Patch attached against 7.x-1.x.

khanz’s picture

facing the same issue..

daniel-san’s picture

Was receiving same error on creation of node where a prepopulate argument isn't passed in the URL.

Patch in #5 seems to work well.

Thank you for working on this.

micnap’s picture

Ditto daniel-san.

hefox’s picture

My guess is whatever is calling that function is suppose to be passing in $items an array and that the error may be from the calling function instead. Not experiencing this error so haven't looked inot

hefox’s picture

Issue summary: View changes

correction

Chris Matthews’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

The 6 year old patch in #5 to entityreference.module does not apply to the latest 7.x-1.x-dev and if still relevant needs a reroll.

Checking patch entityreference.module...
error: while searching for:
    $entity_labels = array();

    // Build an array of entities ID.
    foreach ($items as $item) {
      $entity_ids[] = $item['target_id'];
    }

    // Load those entities and loop through them to extract their labels.

error: patch failed: entityreference.module:812
error: entityreference.module: patch does not apply