diff --git a/core/lib/Drupal/Core/Entity/ContentEntityType.php b/core/lib/Drupal/Core/Entity/ContentEntityType.php index c4033b5dbb..0e26c3bb51 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityType.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityType.php @@ -14,11 +14,6 @@ class ContentEntityType extends EntityType implements ContentEntityTypeInterface */ protected $revision_metadata_keys = []; - /** - * {@inheritdoc} - */ - protected $supports_validation = TRUE; - /** * {@inheritdoc} */ diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index 1132a7a6eb..5f6589a6b4 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -277,13 +277,6 @@ class EntityType extends PluginDefinition implements EntityTypeInterface { */ protected $additional = []; - /** - * Entity type supports validation. - * - * @var bool - */ - protected $supports_validation = FALSE; - /** * Constructs a new EntityType. * diff --git a/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php b/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php index d21a2a89ef..4fa05b6516 100644 --- a/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php +++ b/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php @@ -20,7 +20,7 @@ * * @ingroup entity_api */ -interface FieldableEntityInterface extends EntityInterface { +interface FieldableEntityInterface extends EntityInterface, ValidatableInterface { /** * Provides base field definitions for an entity type. @@ -209,31 +209,4 @@ public function getTranslatableFields($include_computed = TRUE); */ public function onChange($field_name); - /** - * Validates the currently set values. - * - * @return \Drupal\Core\Entity\EntityConstraintViolationListInterface - * A list of constraint violations. If the list is empty, validation - * succeeded. - */ - public function validate(); - - /** - * Checks whether entity validation is required before saving the entity. - * - * @return bool - * TRUE if validation is required, FALSE if not. - */ - public function isValidationRequired(); - - /** - * Sets whether entity validation is required before saving the entity. - * - * @param bool $required - * TRUE if validation is required, FALSE otherwise. - * - * @return $this - */ - public function setValidationRequired($required); - } diff --git a/core/lib/Drupal/Core/Entity/ValidatableInterface.php b/core/lib/Drupal/Core/Entity/ValidatableInterface.php new file mode 100644 index 0000000000..3fded8b78e --- /dev/null +++ b/core/lib/Drupal/Core/Entity/ValidatableInterface.php @@ -0,0 +1,39 @@ +entityType->get('supports_validation')) { + if (!$this->entityType->entityClassImplements(ValidatableInterface::class)) { $unsupported_methods = ['POST', 'PUT', 'DELETE', 'PATCH']; $methods = array_diff($methods, $unsupported_methods); } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index 49b22ef675..e20bf5a24b 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -7,6 +7,7 @@ use Drupal\Core\Cache\CacheableResponseInterface; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\FieldableEntityInterface; +use Drupal\Core\Entity\ValidatableInterface; use Drupal\Core\Url; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -689,7 +690,7 @@ protected static function recursiveKSort(array &$array) { * Tests a POST request for an entity, plus edge cases to ensure good DX. */ public function testPost() { - if (!$this->entity->getEntityType()->get('supports_validation')) { + if (!$this->entity->getEntityType()->entityClassImplements(ValidatableInterface::class)) { $this->assertTrue(TRUE, "This entity type doesn't support POSTing."); return; } @@ -930,7 +931,7 @@ public function testPost() { * Tests a PATCH request for an entity, plus edge cases to ensure good DX. */ public function testPatch() { - if (!$this->entity->getEntityType()->get('supports_validation')) { + if (!$this->entity->getEntityType()->entityClassImplements(ValidatableInterface::class)) { $this->assertTrue(TRUE, "This entity type doesn't support PATCHing."); return; } @@ -1150,7 +1151,7 @@ public function testPatch() { * Tests a DELETE request for an entity, plus edge cases to ensure good DX. */ public function testDelete() { - if (!$this->entity->getEntityType()->get('supports_validation')) { + if (!$this->entity->getEntityType()->entityClassImplements(ValidatableInterface::class)) { $this->assertTrue(TRUE, "This entity type doesn't support DELETEing."); return; }