Problem/Motivation

Sibling issue for simple config: #2952037: [meta] Add constraints to all simple configuration.

Now that we have the possibilities to validate configuration we should do that.
This meta issue is about adding constrains to all config entities, so we can use that in JSON:API as well as in configuration entity forms.

The current list of config entity types in core:

  1. core.base_field_override.*.*.*: #3324140: Convert field_storage_config and field_config's form validation logic to validation constraints
  2. field.field.*.*.*: #3324140: Convert field_storage_config and field_config's form validation logic to validation constraints
  3. core.date_format.*: #3397491: Add validation constraints to core.date_format.*
  4. core.entity_view_mode.*.*: #3445150: Add validation constraints to core.entity_view_mode.*.*
  5. core.entity_view_display.*.*.*
  6. core.entity_form_mode.*.*:#3448457: Add validation constraints to core.entity_form_mode.*.*
  7. core.entity_form_display.*.*.*
  8. block.block.*: #3379725: Make Block config entities fully validatable
  9. block_content.type.*: #3397493: Add validation constraints to block_content.type.*
  10. comment.type.*: #3455066: Add validation constraints to comment.type.*
  11. editor.editor.*: #3412361: Mark Editor config schema as fully validatable
  12. field.storage.*.*: #3324140: Convert field_storage_config and field_config's form validation logic to validation constraints
  13. filter.format.*: #3421946: [PP-2] Make FilterFormat config entities fully validatable
  14. image.style.*: #3447286: Add validation constraints to image.style.*
  15. language.entity.* #3457766: Add validation constraints to language.entity.*Not in Standard
  16. language.content_settings.*.*#3458321: Add validation constraints to language.content_settings.*.* Not in Standard
  17. node.type.*: #3379091: Make NodeType config entities fully validatable
  18. responsive_image.styles.* Not in Standard
  19. rest.resource.* Not in Standard
  20. search.page.*: #3456133: Add validation constraints to search.page.*
  21. shortcut.set.* — see #3324984-35: Create test that reports % of config entity types (and config schema types) that is validatable
  22. system.menu.* — see #3324984-35: Create test that reports % of config entity types (and config schema types) that is validatable
  23. system.action.*:#3449259: Add validation constraints to system.action.*
  24. taxonomy.vocabulary.*: #2002174: Allow vocabularies to be validated via the API, not just during form submissions
  25. user.role.*: #3445215: Add validation constraints to user.role.*
  26. views.view.*
  27. workflows.workflow.*: #2920441: Add config validation for workflow entities Not in Standard

Total: 13/28=46%
Standard: 11/23=48%

Last updated: July 23, 2024.

Related issues

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

dawehner created an issue. See original summary.

dawehner’s picture

Here is a suggestion how we can split up the work in some reasonable sized junks:

  • Add one issue for field related stuff: field config, field storage config, entity view modes, view displays, form modes and form displays
  • Add one issue for adding constrains to every bundle entity type (vocabulary, node types ...)
  • Add one for each test one
  • Maybe one for all the other ones?
dawehner’s picture

wim leers’s picture

Title: Add constrains to all config entities » Add constraints to all config entities
Issue tags: +API-First Initiative
dawehner’s picture

Added a related issue which ideally we fix first: #2869809: Make it easy to get typed config representations of entities to make testing it easier.

tstoeckler’s picture

So I guess this is not as interesting to the Rest folks, and I guess should be a (single ?) separate issue, anyway, but we should add constraints to simple (i.e. non-config-entity) configuration, as well, I guess.

dawehner’s picture

Oh good point, I'm wondering whether we should integrate the constrains into methods as well?

tstoeckler’s picture

Can you clarify #7? Not sure what you mean by "methods". We already have ConfigInterface::save($has_trusted_data) so we could to config validation if $has_trusted_data is FALSE, but that would be kind of a behavior change as that is currently the default.

dawehner’s picture

Oh good point, I'm wondering whether we should integrate the constrains into methods as well?

No idea what I was smoking.

Can you clarify #7? Not sure what you mean by "methods". We already have ConfigInterface::save($has_trusted_data) so we could to config validation if $has_trusted_data is FALSE, but that would be kind of a behavior change as that is currently the default.

Yeah that is a good idea. Wherever we apply config schema validation we should apply config constrain validation as well.

dawehner’s picture

Issue summary: View changes

I started with a small subissue: #2870878: Add config validation for UUIDs

wim leers’s picture

wim leers’s picture

We said at #2300677-115: JSON:API POST/PATCH support for fully validatable config entities.15 that this can happen in parallel with that. But I'm actually not entirely sure that that makes sense — without the ability to add REST test coverage, I'm not sure how much can be done in this issue's child issues?

dawehner’s picture

Well, we could totally write test coverage for those constraints. To be honest I think its even much easier to wrote those constrains instead of writing REST level tests.

wim leers’s picture

WFM :)

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

Title: Add constraints to all config entities » Add constraints to all config entity types
wim leers’s picture

Issue tags: +Entity validation
sam152’s picture

I've created #2920441: Add config validation for workflow entities to cover the workflow config entity. I think given we're doing a lot of validation at the API level, it'll be an interesting challenge to try and cover these same scenarios as constraints and might serve as a road-test of the API in preparation for #2300677: JSON:API POST/PATCH support for fully validatable config entities.

sam152’s picture

Issue summary: View changes
sam152’s picture

Issue summary: View changes
dawehner’s picture

Issue summary: View changes

@Sam152

sam152’s picture

That looks better, thanks.

sam152’s picture

Issue summary: View changes
sam152’s picture

Issue summary: View changes

The first property to validate was the ID, which applies to lots of entity types. Adding to the list of generic validations.

sam152’s picture

Issue summary: View changes

Next cab off the rank is also something which I think is generic.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

effulgentsia’s picture

Priority: Normal » Major
Issue tags: +blocker

Promoting this to Major, because it's a blocker to #2300677: JSON:API POST/PATCH support for fully validatable config entities.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

sime’s picture

I was looking at using configuration constraints based on what I see in system.sites.yml:

    uuid:
      type: uuid
      label: 'Site UUID'
      constraints:
        Uuid: []
        NotNull: []

I experimented with this type of configuration for the site uuid, and for the site name and I was unable to trigger and validation errors. I tried setting values in the UI, config import/export and drush config-set.

Is that a not fully implemented feature? Or is this "constraints:" setting being used in a way that is not obvious? I realise this issue is about config entities, but it seems a good place to discuss since the IS links to the issue that introduced that Uuid: [] line.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

wim leers’s picture

I only now re-discovered this issue 😬

See #2164373-34: [META] Untie config validation from form validation — enables validatable Recipes, decoupled admin UIs … for a summary of the progress in the last month. And also especially see #3324984: Create test that reports % of config entity types (and config schema types) that is validatable, where it becomes possible to automatically track how much work remains!

I think we should consider closing this in favor of #2164373.

Thoughts?

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

wim leers’s picture

Issue summary: View changes
Issue tags: +Configuration schema, +validation

Actually, #2164373 is getting impractically broad. Let's keep this for coordinating for config entity types.

wim leers’s picture

wim leers’s picture

Issue summary: View changes

Great news!

Per #3324984-35: Create test that reports % of config entity types (and config schema types) that is validatable, system.menu.* and shortcut.set.* are done!

They look like this:

system.menu.*:
  type: config_entity
  label: 'Menu'
  mapping:
    id:
      type: machine_name
      label: 'ID'
      # Menu IDs are specifically limited to 32 characters, and allow dashes but not
      # underscores.
      # @see \Drupal\menu_ui\MenuForm::form()
      constraints:
        Regex:
          pattern: '/^[a-z0-9-]+$/'
          message: "The %value machine name is not valid."
        Length:
          max: 32
    label:
      type: required_label
      label: 'Label'
    description:
      type: label
      label: 'Menu description'
    locked:
      type: boolean
      label: ''

and:

shortcut.set.*:
  type: config_entity
  label: 'Shortcut settings'
  mapping:
    id:
      type: machine_name
      label: 'ID'
      # Shortcut set IDs are specifically limited to 23 characters, and allow
      # dashes but not underscores.
      # @see \Drupal\shortcut\ShortcutSetForm::form()
      constraints:
        Regex:
          pattern: '/^[a-z0-9-]+$/'
          message: "The %value machine name is not valid."
        Length:
          max: 23
    label:
      type: required_label
      label: 'Label'

They are very simple config entity types for sure, but … hey, we've got to start somewhere! 😊

EDIT: this means #2300677 is unblocked, see #2300677-260: JSON:API POST/PATCH support for fully validatable config entities 🚀

borisson_’s picture

Issue summary: View changes
wim leers’s picture

Issue summary: View changes
wim leers’s picture

Issue summary: View changes
wim leers’s picture

Title: Add constraints to all config entity types » [meta] Add constraints to all config entity types
Issue summary: View changes
Related issues: +#2952037: [meta] Add constraints to all simple configuration
wim leers’s picture

wim leers’s picture

Issue summary: View changes
wim leers’s picture

Issue summary: View changes

Since #42: one more landed (DateFormat), two more in progress (Editor and Vocabulary)!

wim leers’s picture

Issue summary: View changes

RDF is removed. Test-only config entity types do not necessarily need this IMHO. Let's tighten the scope to config entity types that are actually used in this meta.

wim leers’s picture

Issue summary: View changes

Forgot that BlockContentType also landed!

wim leers’s picture

Issue summary: View changes
wim leers’s picture

Issue summary: View changes

I got #2920441: Add config validation for workflow entities started too — now 100% of the issues listed in the issue summary have an in-progress MR, some RTBC, some nearly, some with still a long way to go.

Progress! 😊

wim leers’s picture

wim leers’s picture

wim leers’s picture

Issue summary: View changes

#3379725: Make Block config entities fully validatable is moving forward — probably one of the most important config entity types to make validatable because most sites have a fairly large number of these.

wim leers’s picture

Issue summary: View changes

The list has gotten shorter thanks to #3422600: Remove Tour module 🤓

wim leers’s picture

Issue summary: View changes

Cleaned up, and now with detailed statistics:
Total: 7/28=25%
Standard: 7/23=30%

(just like the sibling issue #2952037: [meta] Add constraints to all simple configuration)

narendrar’s picture

Issue summary: View changes
narendrar’s picture

Issue summary: View changes
narendrar’s picture

Issue summary: View changes
wim leers’s picture

Issue summary: View changes

image.style.* is in!

mtift’s picture

Issue summary: View changes
narendrar’s picture

Issue summary: View changes
narendrar’s picture

Issue summary: View changes
narendrar’s picture

Issue summary: View changes
wim leers’s picture

Issue summary: View changes

3 more config entity types are now fully validatable! 🚀

phenaproxima’s picture

phenaproxima’s picture

wim leers’s picture

Issue summary: View changes

Updating for #68 + #69.

bbrala’s picture

When working on #2300677: JSON:API POST/PATCH support for fully validatable config entities i did notice after actually enabling tests for all validatable config entities, that although system.action.* is validated, the plugins aren't. So when testing, using user_unblock_user_action it errors on that fact.

Not sure if would have marked action as validatable when the configuration you might be able to put in there (from core) is not.

borisson_’s picture

Well, system.action.* is fully validatable, but you are right that the plugins aren't.
Depending on the metric you use, all the config in core is at around 42% validatability. https://project.pages.drupalcode.org/config_inspector/

So, if we would have to keep all the plugins in mind as well, I think we would probably have to remove even more of the checkmarks from this list. I don't think we have open issues for all the plugins, but I guess we can create those issues to make the plugin validatable again.

bbrala’s picture

Issue summary: View changes
bbrala’s picture

bbrala’s picture

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

borisson_’s picture

Issue summary: View changes

Removed contact from the list, now that's no longer in core.