Skip to content
Snippets Groups Projects
Commit 522ed005 authored by catch's avatar catch
Browse files

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
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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"');
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment