From fafda5f04803909e043f89a0d7d7389ac846b1fb Mon Sep 17 00:00:00 2001 From: xjm <xjm@65776.no-reply.drupal.org> Date: Wed, 27 Mar 2019 18:37:00 -0500 Subject: [PATCH] Issue #3043687 by phenaproxima, tim.plunkett, johndevman: Layout Builder's Quick Edit integration causes fatals when using field blocks for entities other than the one being viewed --- .../src/QuickEditIntegration.php | 2 +- .../Functional/LayoutBuilderQuickEditTest.php | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 core/modules/layout_builder/tests/src/Functional/LayoutBuilderQuickEditTest.php diff --git a/core/modules/layout_builder/src/QuickEditIntegration.php b/core/modules/layout_builder/src/QuickEditIntegration.php index ac6de1296252..b2b9a62210f7 100644 --- a/core/modules/layout_builder/src/QuickEditIntegration.php +++ b/core/modules/layout_builder/src/QuickEditIntegration.php @@ -312,7 +312,7 @@ private function buildEntityView(array &$elements) { * @see \Drupal\layout_builder\Plugin\Block\FieldBlock */ private function supportQuickEditOnComponent(array $component, FieldableEntityInterface $entity) { - if (isset($component['content']['#field_name'], $component['#base_plugin_id']) && $component['#base_plugin_id'] === 'field_block') { + if (isset($component['content']['#field_name'], $component['#base_plugin_id']) && $component['#base_plugin_id'] === 'field_block' && $entity->hasField($component['content']['#field_name'])) { return $entity->getFieldDefinition($component['content']['#field_name'])->isDisplayConfigurable('view'); } return FALSE; diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderQuickEditTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderQuickEditTest.php new file mode 100644 index 000000000000..755c9e5ea993 --- /dev/null +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderQuickEditTest.php @@ -0,0 +1,67 @@ +<?php + +namespace Drupal\Tests\layout_builder\Functional; + +use Drupal\Tests\BrowserTestBase; + +/** + * Tests Layout Builder integration with Quick Edit. + * + * @group layout_builder + */ +class LayoutBuilderQuickEditTest extends BrowserTestBase { + + /** + * {@inheritdoc} + */ + protected static $modules = [ + 'layout_builder', + 'node', + 'quickedit', + ]; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + // Create two nodes. + $this->createContentType([ + 'type' => 'bundle_with_section_field', + 'name' => 'Bundle with section field', + ]); + $this->createNode([ + 'type' => 'bundle_with_section_field', + ]); + } + + /** + * Tests Quick Edit integration with a block from a different entity type. + */ + public function testPlaceFieldBlockFromDifferentEntityType() { + $page = $this->getSession()->getPage(); + + $this->drupalLogin($this->drupalCreateUser([ + 'configure any layout', + 'administer node display', + 'access in-place editing', + ])); + + // From the manage display page, go to manage the layout. + $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default'); + $this->drupalPostForm(NULL, ['layout[enabled]' => TRUE], 'Save'); + $this->drupalPostForm(NULL, ['layout[allow_custom]' => TRUE], 'Save'); + + // Place a field block for a user entity field. + $this->drupalGet('node/1/layout'); + $page->clickLink('Add Block'); + $page->clickLink('Name'); + $page->pressButton('Add Block'); + $page->pressButton('Save layout'); + + $this->drupalGet('node/1'); + $this->assertSession()->statusCodeEquals(200); + } + +} -- GitLab