Commit 522ed005 authored by catch's avatar catch

Issue #2914938 by timmillwood, RajabNatshah, xjm, Manuel Garcia, amateescu,...

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)
parent 968da88d
......@@ -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;
}
......@@ -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"');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment