This backports #2990532: Drupal core compatibility: Terms are now publishable in 8.6+

This will maximize longterm D8 compatibility on the 1.x branch and unblock #3021056: Backport #3005826 to 1.x: JSON API + hook_node_grants() implementations: count queries still result in cacheability metadata leak because this is a contributing factor to 1.x HEAD failing tests.

Comments

gabesullice created an issue. See original summary.

gabesullice’s picture

gabesullice’s picture

Status: Active » Needs review
StatusFileSize
new3.68 KB

This one was the most complicated of the backports because the code in JsonApiDocumentTopLevelNormalizerTest had other changes unrelated to this issue in the source patch. I think I've gotten it. If so, tests should be green for 8.x-1.x on 8.5, 8.6 & 8.7.

gabesullice’s picture

Assigned: gabesullice » Unassigned
Status: Needs review » Needs work

The attached patch fixes 8.6 and 8.7, but breaks on 8.5 (a regression).

It's midnight for me, so I'll let @Wim Leers take over from here.

Once this lands, #3021056: Backport #3005826 to 1.x: JSON API + hook_node_grants() implementations: count queries still result in cacheability metadata leak should be ready to land. So, if it passes after this is in (or only needs minor changes) it's obviously RTBC from me.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new1.91 KB
new3.87 KB
+++ b/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php
@@ -265,10 +265,11 @@ class JsonApiDocumentTopLevelNormalizerTest extends JsonapiKernelTestBase {
-    $this->assertEquals($this->term1->uuid(), $normalized['included'][0]['id']);
-    $this->assertEquals('taxonomy_term--tags', $normalized['included'][0]['type']);
-    $this->assertEquals($this->term1->label(), $normalized['included'][0]['attributes']['name']);
-    $this->assertTrue(!isset($normalized['included'][0]['attributes']['created']));
+    $this->assertEquals($this->term1->uuid(), $normalized['included'][1]['id']);
+    $this->assertEquals('taxonomy_term--tags', $normalized['included'][1]['type']);
+    $this->assertEquals($this->term1->label(), $normalized['included'][1]['attributes']['name']);
+    $this->assertCount(floatval(\Drupal::VERSION) >= 8.6 ? 9 : 8, $normalized['included'][1]['attributes']);
+    $this->assertTrue(!isset($normalized['included'][1]['attributes']['created']));

First, I thought this was porting part of #2843922: Show label of inaccessible entities ('view' access denied) when 'view label' access is allowed … but then I realized that in fact it was simply the set of includes that resolves to a differently ordered list on 8.6 vs 8.5.

  • 8.5: [term1, term2, file]
  • 8.6 and 8.7: [file, term1, term2]

Why? 🤔

On 8.6 + 8.7, iterating over the fields of a Node entity returns field_image, then field_tags. On 8.5, it's the other way around!

To convince yourself, run \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::testNormalize() and put a breakpoint in EntityNormalizerValue:__construct(); make it break on the condition $entity instanceof \Drupal\node\NodeInterface, and then evaluate this:

\Drupal\Core\TypedData\TypedDataInternalPropertiesHelper::getNonInternalProperties($entity->getTypedData())

You'll be able to confirm the different field order.

We could ask "why?" again, but there's no point to it: this is a subtle change in core that does not change the data model, so it is a fair change. I could find the exact core commit that caused this, but there's no point to doing that other than satisfying our curiosity :)

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Green on 8.5+8.6+8.7 ✅

  • Wim Leers committed 41f70b3 on 8.x-1.x
    Issue #3021073 by Wim Leers, gabesullice: Backport #2990532: Terms are...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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