[META] Untie config validation from form validation — enables validatable Recipes, decoupled admin UIs …

Created on 30 December 2013, almost 11 years ago
Updated 28 March 2024, 8 months ago

Problem/Motivation

Parallel issue to #1696648: [META] Untie content entity validation from form validation , but for config. Placing this in the "configuration entity system" component for now, though possibly we want to cover single config as well?

Currently, core does not implement web services (i.e., a REST plugin) for config. However, contrib may wish to. Contrib will have a difficult time doing that if there's no way to validate config independently of a form submission.

Steps to reproduce

N/A

Proposed resolution

To achieve this, use Drupal's existing config schema infrastructure (see the documentation ), which has supported validation constraints

  1. 🟢 → Add validation constraints to config_entity.dependencies Fixed
  2. 🟢 → 📌 Create test that reports % of config entity types (and config schema types) that is validatable Postponed
  3. 🤞 Ideally, get that test committed to Drupal core.
  4. 🟢 → #3324140-8: Convert field_storage_config and field_config's form validation logic to validation constraints
  5. Provide a concrete example of removing validation logic for a config entity form and relying on the validation constraints in the config schema instead.

Want to add validation for one more config type and/or config entity type?

  1. Run the test made available at 📌 Create test that reports % of config entity types (and config schema types) that is validatable Postponed on the current version of Drupal core to identify which config entity types (which correspond to one particular config type, but are "decorated" in an entity) or which config types are not yet validatable. On Jan 1, 2023, 29 of 628 config types were validatable, 0 of 30 config entity types and 1369 of 3732 property paths.
  2. Analyze the ::preSave(), ::postSave(), ::save(), ::validateForm(), ::submitForm() logic, as well as the default config to determine what validation constraints would be appropriate. What is the shape of the data?
  3. Try to reuse existing validation constraints. You can find them by searching Drupal core for @Constraint.
  4. Be very aware that one typically needs more validation logic than is contained in the pre-existing forms, because forms only allow strings to be submitted, and are constrained by the shape of the form. Assume entities are being created through REST/JSON:API/PHP code, which means arbitrary data can be received!
  5. Expand the pre-existing config-entity-type-specific test, to ensure that the expected validation errors are thrown.
  6. Create a follow-up issue that aims to remove the validation logic from the associated form(s) and rewire it to rely on the validation errors. ⚠️ Examples to follow.

User interface changes

None.

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

🌱 Plan
Status

Fixed

Version

11.0 🔥

Component
Configuration entity 

Last updated about 10 hours ago

Created by

🇺🇸United States effulgentsia

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.

Production build 0.71.5 2024