commit 9b6e62411d4594c37e0724813552052072018451 Author: Bevan Wishart <bevan@catalyst-au.net> Date: Mon Jul 22 17:34:10 2019 +1000 Revert prevention of layout exposure to apis diff --git a/core/modules/layout_builder/src/Field/LayoutSectionItemList.php b/core/modules/layout_builder/src/Field/LayoutSectionItemList.php index 58e78f2562..49d3a50717 100644 --- a/core/modules/layout_builder/src/Field/LayoutSectionItemList.php +++ b/core/modules/layout_builder/src/Field/LayoutSectionItemList.php @@ -2,10 +2,8 @@ namespace Drupal\layout_builder\Field; -use Drupal\Core\Access\AccessResult; use Drupal\Core\Field\FieldItemList; use Drupal\Core\Field\FieldItemListInterface; -use Drupal\Core\Session\AccountInterface; use Drupal\layout_builder\Section; use Drupal\layout_builder\SectionListInterface; use Drupal\layout_builder\SectionStorage\SectionStorageTrait; @@ -77,14 +75,4 @@ public function equals(FieldItemListInterface $list_to_compare) { return $convert($this) === $convert($list_to_compare); } - /** - * Overrides \Drupal\Core\Field\FieldItemListInterface::defaultAccess(). - * - * @ingroup layout_builder_access - */ - public function defaultAccess($operation = 'view', AccountInterface $account = NULL) { - // @todo Allow access in https://www.drupal.org/node/2942975. - return AccessResult::forbidden(); - } - } diff --git a/core/modules/layout_builder/src/LayoutBuilderServiceProvider.php b/core/modules/layout_builder/src/LayoutBuilderServiceProvider.php index 71005ee48c..3b11198991 100644 --- a/core/modules/layout_builder/src/LayoutBuilderServiceProvider.php +++ b/core/modules/layout_builder/src/LayoutBuilderServiceProvider.php @@ -5,8 +5,6 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceProviderInterface; use Drupal\layout_builder\EventSubscriber\SetInlineBlockDependency; -use Drupal\layout_builder\Normalizer\LayoutEntityDisplayNormalizer; -use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; @@ -39,14 +37,6 @@ public function register(ContainerBuilder $container) { $definition->addTag('event_subscriber'); $container->setDefinition('layout_builder.get_block_dependency_subscriber', $definition); } - if (isset($modules['serialization'])) { - $definition = (new ChildDefinition('serializer.normalizer.config_entity')) - ->setClass(LayoutEntityDisplayNormalizer::class) - // Ensure that this normalizer takes precedence for Layout Builder data - // over the generic serializer.normalizer.config_entity. - ->addTag('normalizer', ['priority' => 5]); - $container->setDefinition('layout_builder.normalizer.layout_entity_display', $definition); - } } } diff --git a/core/modules/layout_builder/tests/src/Functional/Rest/OverrideSectionsTest.php b/core/modules/layout_builder/tests/src/Functional/Rest/OverrideSectionsTest.php deleted file mode 100644 index 6d01a6803c..0000000000 --- a/core/modules/layout_builder/tests/src/Functional/Rest/OverrideSectionsTest.php +++ /dev/null @@ -1,153 +0,0 @@ -<?php - -namespace Drupal\Tests\layout_builder\Functional\Rest; - -use Drupal\Core\Url; -use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage; -use Drupal\node\Entity\Node; -use GuzzleHttp\RequestOptions; - -/** - * Tests that override layout sections are not exposed via the REST API. - * - * @group layout_builder - * @group rest - */ -class OverrideSectionsTest extends LayoutRestTestBase { - - /** - * {@inheritdoc} - */ - protected static $resourceConfigId = 'entity.node'; - - /** - * {@inheritdoc} - */ - public function setUp() { - parent::setUp(); - // @todo Figure why field definitions have to cleared in - // https://www.drupal.org/project/drupal/issues/2985882. - $this->container->get('entity_field.manager')->clearCachedFieldDefinitions(); - } - - /** - * Tests that the layout override field is not normalized. - */ - public function testOverrideField() { - $this->assertCount(1, $this->node->get(OverridesSectionStorage::FIELD_NAME)); - - // Make a GET request and ensure override field is not included. - $response = $this->request( - 'GET', - Url::fromRoute('rest.entity.node.GET', ['node' => $this->node->id()]) - ); - $this->assertResourceResponse( - 200, - FALSE, - $response, - [ - 'config:filter.format.plain_text', - 'config:rest.resource.entity.node', - 'config:rest.settings', - 'http_response', - 'node:1', - ], - [ - 'languages:language_interface', - 'theme', - 'url.site', - 'user.permissions', - ], - FALSE, - 'MISS' - ); - $get_data = $this->getDecodedContents($response); - $this->assertSame('A node at rest will stay at rest.', $get_data['title'][0]['value']); - $this->assertArrayNotHasKey('layout_builder__layout', $get_data); - - // Make a POST request without the override field. - $new_node = [ - 'type' => [ - [ - 'target_id' => 'bundle_with_section_field', - ], - ], - 'title' => [ - [ - 'value' => 'On with the rest of the test.', - ], - ], - ]; - $response = $this->request( - 'POST', - Url::fromRoute( - 'rest.entity.node.POST'), - [ - RequestOptions::BODY => $this->serializer->encode($new_node, static::$format), - ] - ); - $this->assertResourceResponse(201, FALSE, $response); - $posted_node = $this->nodeStorage->load(2); - $this->assertEquals('On with the rest of the test.', $posted_node->getTitle()); - - // Make a POST request with override field. - $new_node['layout_builder__layout'] = []; - $post_contents = $this->serializer->encode($new_node, static::$format); - $response = $this->request( - 'POST', - Url::fromRoute( - 'rest.entity.node.POST'), - [ - RequestOptions::BODY => $post_contents, - ] - ); - $this->assertResourceErrorResponse(403, 'Access denied on creating field \'layout_builder__layout\'.', $response); - - // Make a PATCH request without the override field. - $patch_data = [ - 'title' => [ - [ - 'value' => 'New and improved title', - ], - ], - 'type' => [ - [ - 'target_id' => 'bundle_with_section_field', - ], - ], - ]; - $response = $this->request( - 'PATCH', - Url::fromRoute( - 'rest.entity.node.PATCH', - ['node' => 1] - ), - [ - RequestOptions::BODY => $this->serializer->encode($patch_data, static::$format), - ] - ); - $this->assertResourceResponse(200, FALSE, $response); - $this->nodeStorage->resetCache([1]); - $this->node = $this->nodeStorage->load(1); - $this->assertEquals('New and improved title', $this->node->getTitle()); - - // Make a PATCH request with the override field. - $patch_data['title'][0]['value'] = 'This title will not save.'; - $patch_data['layout_builder__layout'] = []; - $response = $this->request( - 'PATCH', - Url::fromRoute( - 'rest.entity.node.PATCH', - ['node' => 1] - ), - [ - RequestOptions::BODY => $this->serializer->encode($patch_data, static::$format), - ] - ); - - $this->assertResourceErrorResponse(403, 'Access denied on updating field \'layout_builder__layout\'.', $response); - // Ensure the title has not changed. - $this->assertEquals('New and improved title', Node::load(1)->getTitle()); - } - -}