Problem/Motivation

Surfaced at #3397493: Add validation constraints to block_content.type.*, specifically at https://git.drupalcode.org/project/drupal/-/merge_requests/5170/diffs#no...

#3404061: When setting `NotNull` constraint on type: required_label, two validation errors appear 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.

Issue fork drupal-3413144

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Issue summary: View changes
Status: Active » Needs review
wim leers’s picture

This relates to #3364109: Configuration schema & required values: add test coverage for `nullable: true` validation support and so I linked this issue from the change record from that cluster of issues: https://www.drupal.org/node/3404425

wim leers’s picture

Issue summary: View changes
phenaproxima’s picture

Status: Needs review » Needs work
wim leers’s picture

Assigned: Unassigned » wim leers

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.