Improve NotBlank DX in config (schema) validation

Created on 8 January 2024, 12 months ago

Problem/Motivation

Surfaced at πŸ“Œ Add validation constraints to block_content.type.* Needs work , specifically at https://git.drupalcode.org/project/drupal/-/merge_requests/5170/diffs#no...

πŸ› When setting `NotNull` constraint on type: required_label, two validation errors appear Needs review improved the DX for using NotBlank in the "required value" case.

But turns out that in the "optional value" case, we can improve it too!

Steps to reproduce

Proposed resolution

Always set $constraints['NotBlank']['allowNull'] = TRUE; because:

  1. when it is required (i.e. nullable: false, which is the default), null will trigger the NotNull constraint, and NotBlank should not generate an equivalent message again
  2. when it is optional (i.e. nullable: true, which must be explicitly specified), then null is a valid value and NotBlank should not complain

Remaining tasks

  1. βœ… Tweak the infrastructure.
  2. βœ… Prove the DX impact by simplifying node.schema.yml.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

None.

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
ConfigurationΒ  β†’

Last updated 3 days ago

Created by

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

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024