Problem/Motivation

CER module is installed and configured on a D8 site. While migrating a D6 nodes into the D8 site, the corresponding entity may not be available yet. CER seems to assume that the corresponding entity is available and breaks the migration with:

Argument 2 passed to                                                                         [error]
Drupal\corresponding_reference\Entity\CorrespondingReference::synchronizeCorrespondingField()
must implement interface Drupal\Core\Entity\FieldableEntityInterface, null given, called in
/Users/erikstielstra/www/drupal8/docroot/modules/custom/corresponding_reference/src/Entity/CorrespondingReference.php
on line 249 and defined CorrespondingReference.php:302

Proposed resolution

A simple 'if' wrapper in code could be sufficient.

CommentFileSizeAuthor
#2 cer-breaks-migration-2861834-2.patch798 bytesSutharsan
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sutharsan created an issue. See original summary.

Sutharsan’s picture

This change made the migration work.

maijs’s picture

Status: Active » Needs review

This error also occurs when a referenced entity (B) is deleted while an entity (A) which references the entity B is being edited and then saved. At that point the referenced entity is no longer available, and it causes TypeError to be thrown: TypeError: Argument 2 passed to Drupal\cer\Entity\CorrespondingReference::synchronizeCorrespondingField() must implement interface Drupal\Core\Entity\FieldableEntityInterface, null given, called in /Users/xyz/Sites/xyz/web/modules/contrib/cer/src/Entity/CorrespondingReference.php on line 249 in Drupal\cer\Entity\CorrespondingReference->synchronizeCorrespondingField() (line 296 of modules/contrib/cer/src/Entity/CorrespondingReference.php).

The patch in #2 does fix the issue.

maijs’s picture

Title: Breaks migration when corresponding entity is not available yet » An error is thrown if corresponding entity is not available

Changing the title as the issue is broader than initially thought.

bmcclure’s picture

Thanks for finding this issue, and the simple solution posted! It looks good to me.

  • bmcclure committed 326af09 on 8.x-4.x authored by Sutharsan
    Issue #2861834 by Sutharsan, maijs: An error is thrown if corresponding...
bmcclure’s picture

Status: Needs review » Fixed

Thanks for the patch! And also thanks for testing and confirming the larger issue maijs! Should be fixed in the dev version now, and rolled up to a new release version soon.

Status: Fixed » Closed (fixed)

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