diff --git a/core/modules/quickedit/quickedit.module b/core/modules/quickedit/quickedit.module index 3d270500789ffc0da05b50998e3ace7b4d0b0a94..ad08fc1e0df6af4d93cc26d06c0af415df901a1a 100644 --- a/core/modules/quickedit/quickedit.module +++ b/core/modules/quickedit/quickedit.module @@ -180,18 +180,16 @@ function quickedit_entity_view_alter(&$build, EntityInterface $entity, EntityVie * @internal */ function _quickedit_entity_is_latest_revision(ContentEntityInterface $entity) { - $entity_type_manager = \Drupal::entityTypeManager(); - $entity_definition = $entity_type_manager->getDefinition($entity->getEntityTypeId()); - if (!$entity_definition->isRevisionable()) { + if (!$entity->getEntityType()->isRevisionable() || $entity->isNew()) { return TRUE; } - $revision_ids = $entity_type_manager + + $latest_revision = \Drupal::entityTypeManager() ->getStorage($entity->getEntityTypeId()) ->getQuery() - ->allRevisions() - ->condition($entity_definition->getKey('id'), $entity->id()) - ->sort($entity_definition->getKey('revision'), 'DESC') - ->range(0, 1) + ->latestRevision() + ->condition($entity->getEntityType()->getKey('id'), $entity->id()) ->execute(); - return $entity->getLoadedRevisionId() == array_keys($revision_ids)[0]; + + return !empty($latest_revision) && $entity->getLoadedRevisionId() == key($latest_revision) ? TRUE : FALSE; } diff --git a/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php b/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php index 9ca558a37bcd9abe0508a85e261d4e5ada7a3ad9..6945610db1f69f7595c161e9f59c08d19422710f 100644 --- a/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php +++ b/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php @@ -330,6 +330,13 @@ public function testUserWithPermission() { public function testWithPendingRevision() { $this->drupalLogin($this->editorUser); + // Verify that the preview is loaded correctly. + $this->drupalPostForm('node/add/article', ['title[0][value]' => 'foo'], 'Preview'); + $this->assertResponse(200); + // Verify that quickedit is not active on preview. + $this->assertNoRaw('data-quickedit-entity-id="node/' . $this->testNode->id() . '"'); + $this->assertNoRaw('data-quickedit-field-id="node/' . $this->testNode->id() . '/title/' . $this->testNode->language()->getId() . '/full"'); + $this->drupalGet('node/' . $this->testNode->id()); $this->assertRaw('data-quickedit-entity-id="node/' . $this->testNode->id() . '"'); $this->assertRaw('data-quickedit-field-id="node/' . $this->testNode->id() . '/title/' . $this->testNode->language()->getId() . '/full"'); @@ -340,6 +347,7 @@ public function testWithPendingRevision() { $this->testNode->save(); $this->drupalGet('node/' . $this->testNode->id()); + $this->assertResponse(200); $this->assertNoRaw('data-quickedit-entity-id="node/' . $this->testNode->id() . '"'); $this->assertNoRaw('data-quickedit-field-id="node/' . $this->testNode->id() . '/title/' . $this->testNode->language()->getId() . '/full"'); }