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
Comment | File | Size | Author |
---|---|---|---|
#6 | interdiff.txt | 915 bytes | nedjo |
#6 | field_collection_migrate_notice_php_71-3009729-6.patch | 877 bytes | nedjo |
Comments
Comment #2
SpokjeAttached patch should fix the notice.
Comment #3
SpokjeComment #4
SpokjeBetter patch attached.
Comment #5
jacob.embree CreditAttribution: jacob.embree at St. Louis Integration commentedTagging and setting parent issue.
Comment #6
nedjoThanks for this patch. I found the
$entity_array
variable name a bit confusing. Infield_collection_item_add()
infield_collection.pages.inc
we have closely parallel code:Here is an updated patch to use the same approach as there. Updating issue summary accordingly.
Comment #7
nedjoAdding a note to the issue summary about why we can't use
entity_load_single()
here.Comment #8
Liam MorlandThe 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.
Comment #10
nedjoApplied, thanks!