New config schema data type: `required_label`

Created on 14 February 2023, almost 2 years ago
Updated 17 August 2023, over 1 year ago

Problem/Motivation

Virtually every configuration entity has a label. There is no validation on this at all. There is a lot of freedom in what this string contains, but one thing is certain: โ€” the label of a configuration entity should not be empty, but some type: label occurrences are allowed to be empty โ€” for example the site slogan or a field formatter's prefix/suffix.

Proposed resolution

(see @alexpott review in #25) Create a subtype of

# Human readable string that must be plain text and editable with a text field.
label:
  type: string
  label: 'Label'
  translatable: true

that is named required_label and update most configuration entities' labels to use this (exempt: Block, View because they have fallback label logic in their ::label() method), as well as other non-ambiguous cases.

In other words:

  • keep type: label unchanged: do not add validation constraints to them
  • instead, add a new type: required_label, which all code is then free to adopt

So then we end up with:

  1. type: string = string, NOT translatable
  2. type: label = string, translatable
  3. type: required_label = string, translatable, REQUIRED

(Because optional labels still have a use case, for example field prefix/suffix.)

Impact as measured by ๐Ÿ“Œ Create test that reports % of config entity types (and config schema types) that is validatable Postponed 's ConfigSchemaValidatabilityTest (and diff before26.txt after26.txt):

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None. The data model evolves though, to eventually, in the distant future of ๐ŸŒฑ [META] Untie config validation from form validation โ€” enables validatable Recipes, decoupled admin UIs โ€ฆ Active allow for config schema-powered validation:

  1. all configuration entities that have labels now use type: required_label instead of type: label, and have test coverage to prove this indeed triggers a validation error if config validation is executed (which happens ONLY in these tests for now)
  2. 5 non-config entity examples were updated:
    1. mail:subject (rationale: https://git.drupalcode.org/project/drupal/-/merge_requests/3690/diffs#no...), which also required a matching form definition change
    2. type: field.formatter.settings.timestamp_ago's future_format and past_format (rationale: https://git.drupalcode.org/project/drupal/-/merge_requests/3690/diffs#no...), which also required a matching form definition change โ€” without this change invalid configuration was allowed that results in broken behavior!
    3. type: field.formatter.settings.datetime_time_ago: same as the above, because its logic is inherited from the above
    4. type: field.field_settings.boolean's on_label and off_label (rationale: see above), which did NOT require a matching form definition change: BooleanItem::fieldSettingsForm() was already correctly marking these as required ๐Ÿ‘
    5. user.settings:anonymous, which did NOT require a matching form definition change: AccountSettingsForm::buildForm was already correctly marking these as required ๐Ÿ‘

    The first 3 show how widespread the problem is of implicitly required config, and how it can result in broken sites.

  3. all other config is free to start adopting this new config schema type too, but it will have no effect for now

Note: this is only a theoretical data model change. Implicitly, many things in Drupal core assume all config entities have labels. See @kristiaanvandeneynde's comment at #58 for an example.

Release notes snippet

New config schema type: required_label. This is the required variant of the label type, to be able to distinguish between the pre-existing config schema type label (translatable string, MAY be an empty string) and when a string must be translatable and is required (MUST NOT be an empty string).

๐Ÿ“Œ Task
Status

Fixed

Version

11.0 ๐Ÿ”ฅ

Component
Configuration entityย  โ†’

Last updated 4 days ago

Created by

๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

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