Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When a field doesn't have a widget and you save the config it doesn't return an array as defaultValuesFormSubmit
is expected to return and then this error will show:
Warning: Invalid argument supplied for foreach() in Drupal\Core\Field\EntityReferenceFieldItemList->defaultValuesFormSubmit() (line 111 of core/lib/Drupal/Core/Field/EntityReferenceFieldItemList.php).
This shows up for me when I use feeds and the feed_item field is saved but it could be any field without a widget.
Proposed resolution
Return an array from defaultValuesFormSubmit
, always.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#6 | 3071765-6-return-array.patch | 1.08 KB | joelpittet |
Comments
Comment #2
joelpittetHere's the one line patch that satisfies the return value on the interface. I expect this doesn't need tests to verify because PHPstorm picks it up as a bug already and all other cases of this return an empty array that extend this method.
Comment #3
andypostLooks duplicate of related
Comment #5
joelpittet@andypost I don't think this is related. This one doesn't have a widget and it throws warnings because the expected array is NULL which it should be.
Comment #6
joelpittetFixed the broken test.
defaultValuesFormSubmit
should always return an array like it's interface says.Comment #7
joelpittetClarify the title which is where it sounded like the other issue I think
Comment #8
andypostFixed test illustrative
Comment #10
larowlanCommitted dbb87e1 and pushed to 8.8.x. Thanks!
Decided not to backport in case this is disruptive - as although the interface specifies the return should be an array, this is a behaviour change.