diff --git a/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php b/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php index 7df42946d93950a285366464b903adf9138d1b54..4e0f881e1c20f2cb414829e94701b922e94082c2 100644 --- a/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php +++ b/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php @@ -95,6 +95,13 @@ protected function serializeField($field, array $context, $format) { return $normalized_field->withCacheableDependency(CacheableMetadata::createFromObject($field_access_result)); } else { + // @todo Replace this workaround after https://www.drupal.org/node/3043245 + // or remove the need for this 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/LayoutBuilderEntityViewDisplayTest.php b/core/modules/layout_builder/tests/src/Functional/JsonApi/LayoutBuilderEntityViewDisplayTest.php new file mode 100644 index 0000000000000000000000000000000000000000..92c9fb55b5207a29f50411a4310397dbeebbad45 --- /dev/null +++ b/core/modules/layout_builder/tests/src/Functional/JsonApi/LayoutBuilderEntityViewDisplayTest.php @@ -0,0 +1,49 @@ +<?php + +namespace Drupal\Tests\layout_builder\Functional\JsonApi; + +use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage; +use Drupal\Tests\jsonapi\Functional\EntityViewDisplayTest; + +/** + * JSON:API integration test for the "EntityViewDisplay" config entity type. + * + * @group jsonapi + * @group layout_builder + */ +class LayoutBuilderEntityViewDisplayTest extends EntityViewDisplayTest { + + /** + * {@inheritdoc} + */ + public static $modules = ['layout_builder']; + + /** + * {@inheritdoc} + */ + protected function createEntity() { + /** @var \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay $entity */ + $entity = parent::createEntity(); + $entity + ->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; + } + +}