Split validation-related methods from FieldableEntityInterface into a separate ValidatableInterface

Created on 6 September 2017, about 7 years ago
Updated 23 February 2024, 9 months ago

Problem/Motivation

✨ [PP-2] POST/PATCH config entities via REST for config entity types that support validation Needs work intends to allow config entities to opt-in into typed data validation, something that only content entities were able to do until now.

Proposed resolution

Allow config entities to support typed data validation by implementing the new ValidatableInterface.

Remaining tasks

Review.

User interface changes

Nope.

API changes

Not really.

Data model changes

Nope.

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
EntityΒ  β†’

Last updated about 13 hours ago

Created by

πŸ‡·πŸ‡΄Romania amateescu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia

    Should have been unpostponed 5 years ago, whoops

  • Assigned to amateescu
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    This blocks ✨ [PP-2] POST/PATCH config entities via REST for config entity types that support validation Needs work .

    IMHO we should also do #2327883-108: Field [storage] config have incomplete settings until they are saved β†’ here, because without it, we won't be able to actually validate some config entities! 😱 (Which is the goal stated in the issue summary.)

    Quoting #2327883-108:

    One thing I definitely hadn't thought of yet so far is how config entity objects may have different values in their runtime state vs their storage state, thanks to \Drupal\Core\Config\Entity\ConfigEntityStorage::mapToStorageRecord()! 😳 Fortunately, only 3 classes in core override it:

    1. \Drupal\Core\Field\FieldConfigStorageBase::mapToStorageRecord()
    2. \Drupal\field\FieldStorageConfigStorage::mapToStorageRecord()
    3. \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplayStorage::mapToStorageRecord()

    … plus 6 in contrib, 5 of which are virtually identical to core's Layout Builder one.

    This means that for config entity validation to work, the infrastructure that provides validation for config entities must also be able to call mapToStorageRecord() not just prior to save, but prior to validation. But that method is currently protected πŸ˜… So we need some way to get config entities into the same state as just before saving. We may want to do that as part of πŸ“Œ Split validation-related methods from FieldableEntityInterface into a separate ValidatableInterface Needs work or in another issue.

    @amateescu, do you have thoughts on how to do that? πŸ€“πŸ™

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Also, ✨ Add validation constraints to config_entity.dependencies Fixed introduced \Drupal\KernelTests\Core\Config\ConfigEntityValidationTestBase::assertValidationErrors() which does:

      protected function assertValidationErrors(array $expected_messages): void {
        /** @var \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data */
        $typed_data = $this->container->get('typed_data_manager');
        $definition = $typed_data->createDataDefinition('entity:' . $this->entity->getEntityTypeId());
        $violations = $typed_data->create($definition, $this->entity)->validate();
    

    We may need to update that for #48.

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Do we really still need this if #1818574: Support config entities in typed data EntityAdapter β†’ already made this possible? This code was committed to Drupal core in 2018:

      public function testValidate() {
        $adapter = ConfigEntityAdapter::createFromEntity($this->entity);
        $violations = $adapter->validate();
    

    Seems this is just a nice-to-have now?

    Not to mention: not every config entity type will actually be validatable (we can guarantee this in core, not in contrib), so the existing ::isValidationRequired() is insufficient. We'd also need ::isValidationSupported() or something like that?

    Demoting priority.

Production build 0.71.5 2024