From b6890803c1b3448f245fb1948e2494b7de24739d Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Mon, 12 Feb 2018 10:57:12 +0000 Subject: [PATCH] Issue #2942497 by scott_euser, timmillwood, malcomio, Berdir: Using content moderation block in preview mode causes EntityStorageException --- .../content_moderation/src/EntityOperations.php | 3 +++ .../tests/src/Functional/ModerationFormTest.php | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/core/modules/content_moderation/src/EntityOperations.php b/core/modules/content_moderation/src/EntityOperations.php index 2da246239c8..e2688601df5 100644 --- a/core/modules/content_moderation/src/EntityOperations.php +++ b/core/modules/content_moderation/src/EntityOperations.php @@ -269,6 +269,9 @@ class EntityOperations implements ContainerInjectionInterface { if (!$this->moderationInfo->isModeratedEntity($entity)) { return; } + if (isset($entity->in_preview) && $entity->in_preview) { + return; + } // If the component is not defined for this display, we have nothing to do. if (!$display->getComponent('content_moderation_control')) { return; diff --git a/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php index 4b483584e49..bb9e92d6ea5 100644 --- a/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php +++ b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\content_moderation\Functional; use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\workflows\Entity\Workflow; +use Drupal\Core\Url; /** * Tests the moderation form, specifically on nodes. @@ -80,6 +81,21 @@ class ModerationFormTest extends ModerationStateTestBase { $this->assertResponse(200); $this->assertField('edit-new-state', 'The node view page has a moderation form.'); + // Preview the draft. + $this->drupalPostForm($edit_path, [ + 'body[0][value]' => 'Second version of the content.', + 'moderation_state[0][state]' => 'draft', + ], t('Preview')); + + // The preview view should not have a moderation form. + $preview_url = Url::fromRoute('entity.node.preview', [ + 'node_preview' => $node->uuid(), + 'view_mode_id' => 'full', + ]); + $this->assertResponse(200); + $this->assertUrl($preview_url); + $this->assertNoField('edit-new-state', 'The node preview page has no moderation form.'); + // The latest version page should not show, because there is still no // pending revision. $this->drupalGet($latest_version_path);