\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.
Comment | File | Size | Author |
---|---|---|---|
#5 | 2840063_WidgetBase_extractFormValues_relies_on_non_guaranteed_return_value_5.patch | 965 bytes | n3or |
#2 | Fix_wrong_return_value_expectations_in_WidgetBase__extractFormValues.patch | 950 bytes | n3or |
error.png | 105.59 KB | n3or |
Issue fork drupal-2840063
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
Comment #2
n3or CreditAttribution: n3or commentedComment #3
n3or CreditAttribution: n3or commentedComment #5
n3or CreditAttribution: n3or commentedRe-added the $key_exists, as the return value can be an array altough the key does not exists.
Comment #6
n3or CreditAttribution: n3or commentedComment #23
beunerd CreditAttribution: beunerd at Abt Associates commentedThis is an old issue, but I ran into something similar when using the [Password Policy](https://www.drupal.org/project/password_policy) module. I *think* this is the appropriate ticket, so I've created an MR with a quick edit to check if the `$value` is an array before trying to set/access its `_original_delta` value.
Comment #24
smustgrave CreditAttribution: smustgrave at Mobomo commentedWill need test coverage also.
Also issue summary should follow standard template