Problem/Motivation
While the content sync export is working properly, the import fails when importing the files (the entity type file).
The returned error is :
[error] TypeError: Drupal\content_sync\Normalizer\FileEntityNormalizer::denormalize(): Return value must be of type ArrayObject|array|string|int|float|bool|null, Drupal\file\Entity\File returned in Drupal\content_sync\Normalizer\FileEntityNormalizer->denormalize() (line 141 of /home/meharga/eclipse-workspaces/mmoda-staging/mmoda-st3/web/modules/contrib/content_sync/src/Normalizer/FileEntityNormalizer.php) #0 /home/meharga/eclipse-workspaces/mmoda-staging/mmoda-st3/vendor/symfony/serializer/Serializer.php(247): Drupal\content_sync\Normalizer\FileEntityNormalizer->denormalize()
Steps to reproduce
- Create a fresh instance of Drupal 10 (in my case 10.3.2)
- Install, enable and configure the module content synchronisation
- Create an article within an image inside (to have a file to export/import)
- Export the full content with "
drush cse -y" (it goes smoothly) - Import the same content with "
drush csi -y" and the error raises ...
Proposed resolution
The method Drupal\content_sync\Normalizer\FileEntityNormalizer->denormalize() is calling Drupal\content_sync\Normalizer\ContentEntityNormalizer->denormalize() which is calling Drupal\serialization\Normalizer\EntityNormalizer->denormalize().
The latter is returning an object while the first one is not expected to return that, an object. It is returning : array|string|int|float|bool|\ArrayObject|NULL
public function denormalize($data, $class, $format = NULL, array $serializer_context = array()): array|string|int|float|bool|\ArrayObject|NULL {
This should be replaced by :
public function denormalize($data, $class, $format = NULL, array $serializer_context = array()): mixed {
As it is the case of the first two methods :
- Drupal\content_sync\Normalizer\FileEntityNormalizer->denormalize()
- Drupal\content_sync\Normalizer\ContentEntityNormalizer->denormalize()
This is already suggested in the issue : Drupal 10 compatibility update
Issue fork content_sync-3486660
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
motame commentedComment #3
motame commentedComment #4
ericvl@motame
Thank you to confirm my remark from 2 years ago :-)
It was correct then and is still correct now.
I"m using this module with this modification in a local patch since then.
Comment #5
motame commented@ericvl, you are welcome !
The fix is absolutely right.
Comment #7
kolin commentedI created an MR for the existing issue branch so it can be applied via composer-patches.
I've tested the change and it works as expected.