Problem/Motivation

The following Notice is thrown when migration field_collections in PHP 7.1

Only variables should be passed by reference File \field_collection\field_collection.migrate.inc, line 97

Proposed resolution

In field_collection_item_add() in field_collection.pages.inc we have closely parallel code:

  $result = entity_load($entity_type, array($entity_id));
  $entity = reset($result);
  if (!$entity) {

Model the relevant lines of migrate code on what's in field_collection_item_add().

Further detail: the problem here is in core's entity_load(), which should have returned a single entity but in Drupal 7 returned an array of entities. This was fixed for D8 in #1160566: entity_load() is actually entity_load_multiple(). To partially address this issue, the Entity API module introduced entity_load_single(). Since Entity API is a dependency of Field Collection, we can use it here--in fact, we already are using it, later in this same method. However, the current code sets the $reset argument to TRUE, and entity_load_single() does not pass that argument when it calls entity_load(), meaning that the default, FALSE, will apply. Therefore, we can't use entity_load_single() here.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Spokje created an issue. See original summary.

Spokje’s picture

Spokje’s picture

Status: Active » Needs review
jacob.embree’s picture

Tagging and setting parent issue.

nedjo’s picture

Thanks for this patch. I found the $entity_array variable name a bit confusing. In field_collection_item_add() in field_collection.pages.inc we have closely parallel code:

  $result = entity_load($entity_type, array($entity_id));
  $entity = reset($result);
  if (!$entity) {

Here is an updated patch to use the same approach as there. Updating issue summary accordingly.

nedjo’s picture

Issue summary: View changes

Adding a note to the issue summary about why we can't use entity_load_single() here.

Liam Morland’s picture

Status: Needs review » Reviewed & tested by the community

The PHP 7.2 failure noted above is fixed in #2936874: PHP7.2 - Deprecated function: each() and is not related to this patch. The "Drush setup of Drupal Failed" failure does not appear to be related to this patch. The other tests are fine.

I have reviewed the code. The patched version has the same functionality, but avoids the issue.

  • nedjo committed 0a33fc6 on 7.x-1.x authored by Spokje
    Issue #3009729 by Spokje, nedjo, jacob.embree, Liam Morland: Notice:...
nedjo’s picture

Status: Reviewed & tested by the community » Fixed

Applied, thanks!

Status: Fixed » Closed (fixed)

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