Problem/Motivation
There are two different ways that a nullable property of a configuration type can be defined, one that uses a custom property name and custom code to evaluate it and one that uses the standard Symfony NotNull constraint.
The first approach uses a boolean 'nullable' property. Example:
# Schema for the entity reference 'default' selection handler settings.
entity_reference_selection.default:
type: entity_reference_selection
label: 'Default selection handler settings'
mapping:
target_bundles:
type: sequence
label: 'types'
nullable: true
This property is set if the item is optional; if not set, the item is required. If the 'nullable' property is used, validation is done on a custom basis in \Drupal\Core\Config\Schema\SchemaCheckTrait::checkValue().
Second, by adding NotNull to an array of constraints. Example:
system.site:
type: config_object
label: 'Site information'
mapping:
uuid:
type: uuid
label: 'Site UUID'
constraints:
Uuid: []
NotNull: []If NotNull is used, the item is required, while if its absent it is presumed to be optional (though, in fact, is required because of the handling of 'nullable'). Validation for NotNull is done via a Symfony constraint.
Proposed resolution
Probably most consistent to standardize on NotNull constraint, but doing so would require changes to almost all configuration items, as the default (not nullable) would now require an explicit NotNull constraint.
Alternately, remove the NotNull constraint on UUID in system.site and, maybe, switch to applying NotNull constraint if 'nullable' property is empty in place of current custom validation code.
Comments
Comment #8
wim leers#3364109: Configuration schema & required values: add test coverage for `nullable: true` validation support has already implemented exactly this! 😄🥳