diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 4e1bf2a..2915609 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -312,6 +312,8 @@ public function isDefaultRevision($new_value = NULL) { if (isset($new_value)) { $this->isDefaultRevision = (bool) $new_value; } + // New entities should always ensure at least one default revision exists, + // creating an entity without a default revision is an invalid state. return $this->isNew() || $return; } diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php index cb73533..aa6295e 100644 --- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php @@ -182,8 +182,8 @@ protected function setUp() { ->method('getFieldDefinitions') ->with($this->entityTypeId, $this->bundle) ->will($this->returnValue($this->fieldDefinitions)); - $this->entity = $this->getMockForAbstractClass('\Drupal\Core\Entity\ContentEntityBase', array($values, $this->entityTypeId, $this->bundle)); + $this->entity = $this->getMockForAbstractClass('\Drupal\Core\Entity\ContentEntityBase', array($values, $this->entityTypeId, $this->bundle), '', TRUE, TRUE, TRUE, ['isNew']); $values['defaultLangcode'] = array(LanguageInterface::LANGCODE_DEFAULT => LanguageInterface::LANGCODE_NOT_SPECIFIED); $this->entityUnd = $this->getMockForAbstractClass('\Drupal\Core\Entity\ContentEntityBase', array($values, $this->entityTypeId, $this->bundle)); } @@ -262,6 +262,12 @@ public function testIsDefaultRevision() { $this->assertTrue($this->entity->isDefaultRevision(FALSE)); // The last call changed the return value for this call. $this->assertFalse($this->entity->isDefaultRevision()); + // The revision for a new entity should always be the default revision. + $this->entity->expects($this->any()) + ->method('isNew') + ->will($this->returnValue(TRUE)); + $this->entity->isDefaultRevision(FALSE); + $this->assertTrue($this->entity->isDefaultRevision()); } /**