diff --git a/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php b/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php index 7df42946d9..430bf0b783 100644 --- a/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php +++ b/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php @@ -95,6 +95,11 @@ protected function serializeField($field, array $context, $format) { return $normalized_field->withCacheableDependency(CacheableMetadata::createFromObject($field_access_result)); } else { + // @todo Remove this work-around in https://www.drupal.org/node/2942975. + // @see \Drupal\layout_builder\Normalizer\LayoutEntityDisplayNormalizer + if ($context['resource_object']->getResourceType()->getDeserializationTargetClass() === 'Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay' && $context['resource_object']->getField('third_party_settings') === $field) { + unset($field['layout_builder']['sections']); + } // Config "fields" in this case are arrays or primitives and do not need // to be normalized. return CacheableNormalization::permanent($field); diff --git a/core/modules/layout_builder/tests/src/Functional/JsonApi/EntityViewDisplayTest.php b/core/modules/layout_builder/tests/src/Functional/JsonApi/EntityViewDisplayTest.php new file mode 100644 index 0000000000..025420dddc --- /dev/null +++ b/core/modules/layout_builder/tests/src/Functional/JsonApi/EntityViewDisplayTest.php @@ -0,0 +1,49 @@ +enableLayoutBuilder() + ->setOverridable() + ->save(); + $this->assertCount(1, $entity->getThirdPartySetting('layout_builder', 'sections')); + return $entity; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedDocument() { + $document = parent::getExpectedDocument(); + array_unshift($document['data']['attributes']['dependencies']['module'], 'layout_builder'); + $document['data']['attributes']['hidden'][OverridesSectionStorage::FIELD_NAME] = TRUE; + $document['data']['attributes']['third_party_settings']['layout_builder'] = [ + 'enabled' => TRUE, + 'allow_custom' => TRUE, + ]; + return $document; + } + +}