Problem/Motivation
Ran into this while working on #3364109: Configuration schema & required values: add test coverage for `nullable: true` validation support.
When the validator validates NULL, it triggers a deprecation error, followed by a nonsensical error message:
"The '' plugin does not exist.
Steps to reproduce
$block = Block::load('block.block.olivero_content');
$block->set('plugin', NULL);
$typed_data = $this->container->get('typed_data_manager');
$definition = $typed_data->createDataDefinition('entity:block');
$violations = $typed_data->create($definition, $block)->validate();
results in:
1x: Deprecated NULL placeholder value for key (@plugin_id) in: "The '@plugin_id' plugin does not exist.". This will throw a PHP error in drupal:11.0.0. See https://www.drupal.org/node/3318826
Proposed resolution
Return early if $value === NULL, just like all other validation constraints: because there is no value to validate.
Remaining tasks
- Test coverage.
- Fix.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
Comments
Comment #3
wim leersComment #4
smustgrave commentedWas pretty easy to review. The test-only feature was already ran and shows the issue.
Using the early return fixed it.
LGTM!
Comment #5
borisson_I agree with @smustgrave, this was pretty easy to review. RTBC++
Comment #6
alexpottCommitted and pushed 156533febb to 11.x and 664f6ffad1 to 10.2.x. Thanks!