diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index c46126e363..85e97f30c4 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -415,6 +415,13 @@ public function validate() { /** * {@inheritdoc} */ + public function isValidated() { + return $this->validated; + } + + /** + * {@inheritdoc} + */ public function isValidationRequired() { return (bool) $this->validationRequired; } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php index d045152f6a..887db66bb8 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityInterface.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityInterface.php @@ -71,4 +71,12 @@ public function getLoadedRevisionId(); */ public function updateLoadedRevisionId(); + /** + * Checks whether the entity has been validated. + * + * @return bool + * TRUE if the entity has been validated, FALSE otherwise. + */ + public function isValidated(); + } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php index bf2a147e0a..847e33f406 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php @@ -200,4 +200,19 @@ public function testCompositeConstraintValidation() { $this->assertEqual($constraint->coversFields(), ['name', 'type'], 'Information about covered fields can be retrieved.'); } + /** + * Tests the isValidated() method on content entities. + */ + public function testIsValidated() { + /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ + $entity = $this->createTestEntity('entity_test_composite_constraint'); + $this->assertFalse($entity->isValidated()); + $entity->validate(); + $this->assertTrue($entity->isValidated()); + $entity->save(); + $this->assertFalse($entity->isValidated()); + $entity->validate(); + $this->assertTrue($entity->isValidated()); + } + }