diff --git a/core/lib/Drupal/Core/Entity/ContentEntityType.php b/core/lib/Drupal/Core/Entity/ContentEntityType.php index c4033b5..0e26c3b 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityType.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityType.php @@ -17,11 +17,6 @@ class ContentEntityType extends EntityType implements ContentEntityTypeInterface /** * {@inheritdoc} */ - protected $supports_validation = TRUE; - - /** - * {@inheritdoc} - */ public function __construct($definition) { parent::__construct($definition); $this->handlers += [ diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index 1132a7a..5f6589a 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -278,13 +278,6 @@ class EntityType extends PluginDefinition implements EntityTypeInterface { protected $additional = []; /** - * Entity type supports validation. - * - * @var bool - */ - protected $supports_validation = FALSE; - - /** * Constructs a new EntityType. * * @param array $definition diff --git a/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php b/core/lib/Drupal/Core/Entity/FieldableEntityInterface.php index d21a2a8..4fa05b6 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 0000000..3fded8b --- /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 f08f780..68b00df 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -9,6 +9,7 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\FieldableEntityInterface; +use Drupal\Core\Entity\ValidatableInterface; use Drupal\Core\Field\Plugin\Field\FieldType\BooleanItem; use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem; use Drupal\Core\Url; @@ -694,7 +695,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; } @@ -935,7 +936,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; } @@ -1165,7 +1166,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; }