WidgetBase::extractFormValues relies on non guaranteed return value

Created on 30 December 2016, almost 8 years ago
Updated 9 January 2024, 12 months ago

\Drupal\Core\Field\WidgetBase::extractFormValues expects $value to be an array, although this is not guaranteed.

This is the affected part:

    // Extract the values from $form_state->getValues().
    $path = array_merge($form['#parents'], array($field_name));
    $key_exists = NULL;
    $values = NestedArray::getValue($form_state->getValues(), $path, $key_exists);
    if ($key_exists) {
..
      // Let the widget massage the submitted values.
      $values = $this->massageFormValues($values, $form, $form_state);

There are cases (as described in the method summary of NestedArray::getValue) in which it returns null but $key_exists is true. Then we get an fatal error, because WidgetBase::massageFormValues receives null as $values.

In this case we have 2 possibilities:

* NestedArray::getValue sets key_exists to false if the return value is null
* WidgetBase::massageFormValues checks not just key_exists but also the expected type

The first possibility conflicts to the method summary of NestedArray::getValue, wherefore I created a patch for the second possibility.

In my patch I also addressed the method return value, which is used as reference.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
FieldΒ  β†’

Last updated 1 day ago

Created by

πŸ‡©πŸ‡ͺGermany n3or Karlsruhe

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024