Problem

The normalization of content entities with a translation fails as the default_langcode property is not handled correctly. This might not be problematic for REST, but is a show stopper for contributed modules which want to use the entity serialization API.

At least, default content module fails with entity translations due to this: #2680135: Support for entities with translations is broken.

Proposed resolution

Fix the core normalizers to handle translations correctly.

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fago created an issue. See original summary.

fago’s picture

Here is patch which fixes the problem for the content entity normalizer of hal module.

Note that the content entity normalizer of serialization will have the same problem as it does not deal with languages at all, but I think the root problem here is the total separation of \Drupal\hal\Normalizer\ContentEntityNormalizer from \Drupal\serialization\Normalizer\ContentEntityNormalizer. The HAL variant should probably extend the serialization one and restrict itself to its own format as I suggested in #2792169: HAL normalizers simply replace the default normalizers. But that re-factoring would be better handled in a separate issue imo.

fago’s picture

Status: Active » Needs review
fago’s picture

Title: Normalization of entities with translations fails » Denormalization of entities with translations fails

Correcting things a bit: What's actually broken is de-normalizing, normalizing works fine.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

We have a fix and passing tests. The code looks good and it also fixed #2680135: Support for entities with translations is broken.

larowlan’s picture

Nice work, this should go into 8.1.x thought as its a bug (and then forward port)

alexpott’s picture

Just confirming the test fails without the patch.

/usr/local/php5/bin/php /private/var/folders/6n/l28wj18d1dn1p1dkhc329z4w0000gp/T/ide-phpunit.php --configuration /Volumes/devdisk/dev/sites/drupal8alt.dev/core/phpunit.xml.dist Drupal\Tests\hal\Kernel\EntityTranslationNormalizeTest /Volumes/devdisk/dev/sites/drupal8alt.dev/core/modules/hal/tests/src/Kernel/EntityTranslationNormalizeTest.php
Testing started at 11:44 ...
PHPUnit 4.8.11 by Sebastian Bergmann and contributors.


Failed asserting that two strings are identical.
Expected :en
Actual   :de
 <Click to see difference>

 /Volumes/devdisk/dev/sites/drupal8alt.dev/core/modules/hal/tests/src/Kernel/EntityTranslationNormalizeTest.php:81
catch’s picture

+++ b/core/modules/hal/tests/src/Kernel/EntityTranslationNormalizeTest.php
@@ -0,0 +1,91 @@
+    \Drupal::service('router.builder')->rebuild();

Is the router rebuild really necessary for the test to pass? Link generation or something?

xjm’s picture

Status: Reviewed & tested by the community » Needs review

NR for #8.

fago’s picture

Indeed, the router rebuild is not necessary.

fago’s picture

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @fago back to RTBC.

fago’s picture

Version: 8.2.x-dev » 8.3.x-dev

Moving to 8.3.x.

alexpott’s picture

Version: 8.3.x-dev » 8.2.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed feb3a4d and pushed to 8.3.x. Thanks!

Setting to patch to be ported for cherry-pick to 8.2.x once 8.2.0 is out.

  • alexpott committed feb3a4d on 8.3.x
    Issue #2792205 by fago: Denormalization of entities with translations...
alexpott’s picture

Status: Patch (to be ported) » Fixed

Committed 984f899 and pushed to 8.2.x. Thanks!

  • alexpott committed 984f899 on 8.2.x
    Issue #2792205 by fago: Denormalization of entities with translations...

Status: Fixed » Closed (fixed)

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