core/config/schema/core.data_types.schema.yml | 2 +- core/lib/Drupal/Core/Entity/EntityType.php | 2 +- .../src/Plugin/rest/resource/EntityResourceAccessTrait.php | 12 +++++++----- .../Plugin/rest/resource/EntityResourceValidationTrait.php | 1 + .../EntityResource/ConfigTest/ConfigTestResourceTestBase.php | 2 +- .../src/Functional/EntityResource/EntityResourceTestBase.php | 3 ++- .../Drupal/KernelTests/Core/Config/ConfigSchemaTest.php | 2 +- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/core/config/schema/core.data_types.schema.yml b/core/config/schema/core.data_types.schema.yml index 01a1eee..25008f4 100644 --- a/core/config/schema/core.data_types.schema.yml +++ b/core/config/schema/core.data_types.schema.yml @@ -280,7 +280,7 @@ config_entity: constraints: Length: max: 128 - maxMessage: 'UUID: may not be longer than 128 characters.' + maxMessage: 'UUID may not be longer than 128 characters.' langcode: type: string label: 'Language code' diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index 64127a8..97cdda7 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -278,7 +278,7 @@ class EntityType extends PluginDefinition implements EntityTypeInterface { protected $additional = []; /** - * Supports validation of the entity type, useful for REST api support. + * Entity type supports validation. * * @var bool */ diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResourceAccessTrait.php b/core/modules/rest/src/Plugin/rest/resource/EntityResourceAccessTrait.php index cb286dc..4480a85 100644 --- a/core/modules/rest/src/Plugin/rest/resource/EntityResourceAccessTrait.php +++ b/core/modules/rest/src/Plugin/rest/resource/EntityResourceAccessTrait.php @@ -23,14 +23,16 @@ * field. */ protected function checkEditFieldAccess(EntityInterface $entity) { + if (!$entity instanceof FieldableEntityInterface) { + return; + } + // Only check 'edit' permissions for fields that were actually submitted by // the user. Field access makes no difference between 'create' and 'update', // so the 'edit' operation is used here. - if ($entity instanceof FieldableEntityInterface) { - foreach ($entity->_restSubmittedFields as $key => $field_name) { - if (!$entity->get($field_name)->access('edit')) { - throw new AccessDeniedHttpException("Access denied on creating field '$field_name'."); - } + foreach ($entity->_restSubmittedFields as $key => $field_name) { + if (!$entity->get($field_name)->access('edit')) { + throw new AccessDeniedHttpException("Access denied on creating field '$field_name'."); } } } diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResourceValidationTrait.php b/core/modules/rest/src/Plugin/rest/resource/EntityResourceValidationTrait.php index 25a9281..de1bb77 100644 --- a/core/modules/rest/src/Plugin/rest/resource/EntityResourceValidationTrait.php +++ b/core/modules/rest/src/Plugin/rest/resource/EntityResourceValidationTrait.php @@ -40,6 +40,7 @@ protected function validate(EntityInterface $entity) { * Processes violations and creates a helpful exception message. * * @param \Drupal\Core\Entity\EntityConstraintViolationListInterface $violations + * The entity constraint violations to process. * * @throws \Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException * Throws a HTTP exception when the validation fails. diff --git a/core/modules/rest/tests/src/Functional/EntityResource/ConfigTest/ConfigTestResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/ConfigTest/ConfigTestResourceTestBase.php index 60ebb53..8d62290 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/ConfigTest/ConfigTestResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/ConfigTest/ConfigTestResourceTestBase.php @@ -23,7 +23,7 @@ protected $entity; /** - * Countered used internally to have deterministic ids. + * Counter used internally to have deterministic IDs. * * @var int */ diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index 730e655..5c2a99f 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -598,7 +598,7 @@ public function testPost() { $parseable_valid_request_body = $this->serializer->encode($this->getNormalizedPostEntity(), static::$format); $parseable_valid_request_body_2 = $this->serializer->encode($this->getNormalizedPostEntity(), static::$format); $parseable_invalid_request_body = $this->serializer->encode($this->makeNormalizationInvalid($this->getNormalizedPostEntity()), static::$format); - // The normalized structure looks different for fieldable and non fieldable + // The normalized structure is different for fieldable and non-fieldable // entities. if ($this->entity instanceof FieldableEntityInterface) { $parseable_invalid_request_body_2 = $this->serializer->encode($this->getNormalizedPostEntity() + ['uuid' => [$this->randomMachineName(129)]], static::$format); @@ -697,6 +697,7 @@ public function testPost() { $label_field_capitalized = $this->entity->getFieldDefinition($label_field) ->getLabel(); $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\n$label_field: $label_field_capitalized: this field cannot hold more than 1 values.\n", $response); + $request_options[RequestOptions::BODY] = $parseable_invalid_request_body_2; diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php index 7145520..f762816 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php @@ -175,7 +175,7 @@ public function testSchemaMapping() { $expected['mapping']['uuid']['constraints'] = [ 'Length' => [ 'max' => 128, - 'maxMessage' => 'UUID: may not be longer than 128 characters.', + 'maxMessage' => 'UUID may not be longer than 128 characters.', ], ]; $expected['mapping']['langcode']['type'] = 'string';