summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-12-18 14:08:10 (GMT)
committerNathaniel Catchpole2017-12-18 14:08:10 (GMT)
commit522ed00526a604b21a951483e776889332d0b8c4 (patch)
tree2b40e733bf1cb7d7ae9f4997a36f142fff87108f
parent968da88d76bec562783be77df1055762d28a6e42 (diff)
Issue #2914938 by timmillwood, RajabNatshah, xjm, Manuel Garcia, amateescu, Wim Leers: Preview of content - Notice: Undefined offset: 0 in _quickedit_entity_is_latest_revision() (line 196 of core/modules/quickedit/quickedit.module)
-rw-r--r--core/modules/quickedit/quickedit.module16
-rw-r--r--core/modules/quickedit/src/Tests/QuickEditLoadingTest.php8
2 files changed, 15 insertions, 9 deletions
diff --git a/core/modules/quickedit/quickedit.module b/core/modules/quickedit/quickedit.module
index 3d27050..ad08fc1 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 9ca558a..6945610 100644
--- a/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php
+++ b/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php
@@ -330,6 +330,13 @@ class QuickEditLoadingTest extends WebTestBase {
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 @@ class QuickEditLoadingTest extends WebTestBase {
$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"');
}