Commit 0ee25311 authored by catch's avatar catch

Issue #2928778 by plach: Exception when trying to save a new revision after...

Issue #2928778 by plach: Exception when trying to save a new revision after manually setting the original revision ID
parent 0b67173a
......@@ -745,6 +745,12 @@ public function onChange($name) {
elseif (isset($this->translatableEntityKeys[$key][$this->activeLangcode])) {
unset($this->translatableEntityKeys[$key][$this->activeLangcode]);
}
// If the revision identifier field is being populated with the original
// value, we need to make sure the "new revision" flag is reset
// accordingly.
if ($key === 'revision' && $this->getRevisionId() == $this->getLoadedRevisionId()) {
$this->newRevision = FALSE;
}
}
}
......
......@@ -212,4 +212,50 @@ public function testEntityRevisionParamConverter() {
$this->assertNoText('pending revision - en');
}
/**
* Tests manual revert of the revision ID value.
*
* @covers \Drupal\Core\Entity\ContentEntityBase::getRevisionId
* @covers \Drupal\Core\Entity\ContentEntityBase::getLoadedRevisionId
* @covers \Drupal\Core\Entity\ContentEntityBase::setNewRevision
* @covers \Drupal\Core\Entity\ContentEntityBase::isNewRevision
*/
public function testNewRevisionRevert() {
$entity = EntityTestMulRev::create(['name' => 'EntityLoadedRevisionTest']);
$entity->save();
// Check that revision ID field is reset while the loaded revision ID is
// preserved when flagging a new revision.
$revision_id = $entity->getRevisionId();
$entity->setNewRevision();
$this->assertNull($entity->getRevisionId());
$this->assertEquals($revision_id, $entity->getLoadedRevisionId());
$this->assertTrue($entity->isNewRevision());
// Check that after manually restoring the original revision ID, the entity
// is stored without creating a new revision.
$key = $entity->getEntityType()->getKey('revision');
$entity->set($key, $revision_id);
$entity->save();
$this->assertEquals($revision_id, $entity->getRevisionId());
$this->assertEquals($revision_id, $entity->getLoadedRevisionId());
// Check that manually restoring the original revision ID causes the "new
// revision" state to be reverted.
$entity->setNewRevision();
$this->assertNull($entity->getRevisionId());
$this->assertEquals($revision_id, $entity->getLoadedRevisionId());
$this->assertTrue($entity->isNewRevision());
$entity->set($key, $revision_id);
$this->assertFalse($entity->isNewRevision());
$this->assertEquals($revision_id, $entity->getRevisionId());
$this->assertEquals($revision_id, $entity->getLoadedRevisionId());
// Check that flagging a new revision again works correctly.
$entity->setNewRevision();
$this->assertNull($entity->getRevisionId());
$this->assertEquals($revision_id, $entity->getLoadedRevisionId());
$this->assertTrue($entity->isNewRevision());
}
}
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