JSON:API POST/PATCH support for fully validatable config entities

Created on 10 July 2014, over 10 years ago
Updated 19 May 2024, 6 months ago

Problem/Motivation

As an overall issue based on #2292707: GET on entity/taxonomy_vocabulary/{id} is not working it is weird we cannot POST/PATCH/DELETE for config entities.

This was a key reason for the JS Admin UI initiative being unable to proceed: the config it needed to modify was literally impossible to safely modify through APIs — the validation logic lived only in forms!

Proposed resolution

  • ✅ Done in Add validation constraints to config_entity.dependencies Fixed + 📌 Configuration schema & required values: add test coverage for `nullable: true` validation support Fixed .
  • ✅ Implemented in this MR 🥳
  • ✅ This is obsolete thanks to 🌱 [meta] Add constraints to all config entity types Active already having marked multiple config entity types as fully validatable 👍
  • NOTE: Repeating all the validation test coverage from the ConfigEntityValidationTestBase subclasses is pointless. Still, a spot-check makes sense. For that reason, DateFormatTest::testPostValidationErrors() exists. Compare with DateFormatValidationTest and the JSON:API NodeTest::testPostNonExistingAuthor() to verify that this is indeed a consistent DX.

    NOTE: As soon as this lands, every additional config entity type that is marked fully validatable will have its JSON:API functional tests (guaranteed to exist thanks to \Drupal\Tests\jsonapi\Kernel\TestCoverageTest) start failing (guaranteed thanks to ResourceTestBase::setUp() skipping test methods for config entities if and only if the config entity type is NOT fully validatable). That means we will be able to guarantee that everything works consistently 👍

  • ✅ → follow-up: [PP-4] JSON:API DELETE support for config entities Active

Remaining tasks

User interface changes

None.

API changes

  • Addition: \Drupal\Core\Entity\EntityConstraintViolationList now accepts not just FieldableEntityInterface but also ConfigEntityInterface
  • Addition: \Drupal\Core\Config\TypedConfigManager::getOriginalMappingType() (although we could do without; it'd just result in duplication of logic)
  • Change: ConfigEntityAdapter::validate() now returns an \Drupal\Core\Entity\EntityConstraintViolationList instead of a \Symfony\Component\Validator\ConstraintViolationList, to allow config and content entities to be treated consistently.
  • Addition: (@internal) \Drupal\jsonapi\Entity\EntityValidationTrait::validate() now also accepts ConfigEntityInterface and not just FieldableEntityInterface

⚠️ However, any contrib module that:

  1. provides a config entity type (common)
  2. subclasses \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase (uncommon)
  3. has made its config entity type fully validatable (rare)

… will start seeing their tests failing due to their test not yet providing a valid POST or PATCH document for their config entity (these tests were skipped automatically).

Release notes snippet

JSON:API now supports POSTing and PATCHing config entities that are fully validatable. This enables a whole new world of decoupled Drupal applications.

Feature request
Status

Needs work

Version

11.0 🔥

Component
JSON API 

Last updated about 3 hours ago

Created by

🇳🇱Netherlands clemens.tolboom Groningen, 🇳🇱/🇪🇺

Live updates comments and jobs are added and updated live.
  • API addition

    Enhances an existing API or introduces a new subsystem. Depending on the size and impact, possibly backportable to earlier major versions.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024