I am importing an entity reference by label. If entity reference doesn't find a match, it throws an error:

Warning: array_keys() expects parameter 1 to be array, boolean given in entityreference_feeds_set_target() (line 131 of /sites/all/modules/contrib/entityreference/entityreference.feeds.inc).
Warning: reset() expects parameter 1 to be array, null given in entityreference_feeds_set_target() (line 133 of /sites/all/modules/contrib/entityreference/entityreference.feeds.inc).

In the feeds.inc we have:

        case 'label':
          $options = $handler->getReferencableEntities($value, '=');
          $options = reset($options);
          $etids = array_keys($options);
          // Use the first matching entity.
          $entity_id = reset($etids);
          break;

If $options doesn't return a result, the array_keys() line causes an error.

Comments

Rob_Feature’s picture

FileSize
798 bytes
PASSED: [[SimpleTest]]: [MySQL] 121 pass(es). View

This patch is almost certainly not correct, but it fixes it until a better dev comes up with a solution.

derekw’s picture

Issue summary: View changes

Same issue here. This will also occur if the reference exists, but is unpublished (or the importer does not have permission).

tikaszvince’s picture

Status: Active » Reviewed & tested by the community

This patch seems ok.

tucho’s picture

The patch from #1 worked for me.

jshamley’s picture

This patch worked for me as well.

hkovacs’s picture

patch works for me. thanks.

rudiedirkx’s picture

Title: Error during feed import if entity doesn't exist » array_keys() and reset() notices in entityreference_feeds_set_target() during feed import if entity doesn't exist
Priority: Normal » Critical

Patch logic is good, but coding standards are wrong.

How can this still not be fixed? It's so simple. Maintainer, do your thing.

rudiedirkx’s picture

FileSize
851 bytes

Same patch, with correct coding style. For my make file.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 8: entityreference-set-target-notice-1943300-8.patch, failed testing.

Tessa Bakker’s picture

Status: Needs work » Reviewed & tested by the community

Correct code style now and tests are a success!

cdmo’s picture

This patch (#8) also worked for me, no more warnings. Agree that it's RTBC.

jeff.logan’s picture

I can confirm patch #8 works. +1 RTBC

joelpittet’s picture

RTBC +1

  • spotzero committed 56ae458 on 7.x-1.x authored by rudiedirkx
    Issue #1943300 by Rob_Feature, rudiedirkx: array_keys() and reset()...
spotzero’s picture

Status: Reviewed & tested by the community » Fixed

Committed. And just in time for 1.2

Status: Fixed » Closed (fixed)

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