Undefined array key "value" in RequireOnPublishValidator->validate()

Created on 9 February 2024, 5 months ago

Problem/Motivation

The current validator implementation throws a warning for paragraphs with validation errors:

Warning: Undefined array key "value" in Drupal\require_on_publish\Plugin\Validation\Constraint\RequireOnPublishValidator->validate() (line 130 of modules/contrib/require_on_publish/src/Plugin/Validation/Constraint/RequireOnPublishValidator.php).

This happens because this line expects undefined request parameters to be NULL:

$status = $this->request->request->all('status') ?? ['value' => 0];

Symfony's ParameterBag::all() method returns an empty array instead of NULL for undefined parameters:

if (!\is_array($value = $this->parameters[$key] ?? [])) {
  throw new BadRequestException(sprintf('Unexpected value for parameter "%s": expecting "array", got "%s".', $key, get_debug_type($value)));
}

Proposed resolution

  • Handle Symfony's ParameterBag::all() correctly

Remaining tasks

  • Create an issue fork to fix this issue

User interface changes

n/a

API changes

n/a

Data model changes

n/a

🐛 Bug report
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

🇩🇪Germany hctom

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

Comments & Activities

Production build 0.69.0 2024