Error importing nodes that have fields which are Entity References

Created on 4 June 2024, 6 months ago

Problem/Motivation

Creating a field on a page which is an entity reference which points configuration of my contact form this causes some issues for content synchronizer. When exporting the node I can see that the added field is exported like so

"field_contact": [
    {
        "target_id": "feedback"
    }
],

and then when you try importing the content export to a site you will receive the error below

#23 {main}. | user: anonymous | uri: http://<redacted>/ | referer:
TypeError: explode(): Argument #2 ($string) must be of type string, array given in /<redacted>/modules/content_synchronizer/src/Service/GlobalReferenceManager.php on line 144 #0 /<redacted>/modules/content_synchronizer/src/Service/GlobalReferenceManager.php(144): explode()
#1 /<redacted>/modules/content_synchronizer/src/Entity/ImportEntity.php(429): Drupal\content_synchronizer\Service\GlobalReferenceManager->getEntityTypeFromGid()
#2 /<redacted>/modules/content_synchronizer/src/Entity/ImportEntity.php(441): Drupal\content_synchronizer\Entity\ImportEntity->getEntityDataFromGid()
#3 /<redacted>modules/content_synchronizer/src/Plugin/content_synchronizer/type_processor/EntityReferenceFieldItemListProcessor.php(151): Drupal\content_synchronizer\Entity\ImportEntity->gidIsCurrentlyImporting()
#4 /<redacted>/modules/content_synchronizer/src/Processors/Entity/EntityProcessorBase.php(601): Drupal\content_synchronizer\Plugin\content_synchronizer\type_processor\EntityReferenceFieldItemListProcessor->initImportedEntity()

This is because on the import is calls initImportedEntity for the plugin EntityReferenceFieldItemListProcessor and then eventually ends up at the code block

  public function getEntityTypeFromGid($gid) {
    $entityTypeId = explode('.', $gid)[1];
    return $entityTypeId;
  }

Which obviously doesn't make sense as in the above export its not a gid. So I'm not sure if it the export process broken here and it should be exporting the contact form as well and adding the gid into that section of the export like it does for other things or its the import process thats broken and it should be using FieldItemListProcessor to process the Import instead. This is currently a major blocker as its needed to sync config between dev and production sites so would be grateful for any advice and or input

Steps to reproduce

Add an entity reference field to a node under thats located in the configuration category and then try the export/import process

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

4.0

Component

Code

Created by

🇬🇧United Kingdom reece.oliver

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024