Problem/Motivation
When creating/editing a content, using the referenced view field it returns a warning for using an empty array.
Warning: Undefined array key "data" in Drupal\viewsreference\Plugin\Field\FieldType\ViewsReferenceItem->setValue() (line 97 of /var/www/html/web/modules/contrib/viewsreference/src/Plugin/Field/FieldType/ViewsReferenceItem.php)
Steps to reproduce
- Install the module.
- Structure » Content types » Basic page » Manage fields » Add views reference field
- Configure the field (in my case, block and checked some "Preselect View Options")
- Create a new basic page content
- Select random view and check the log
Proposed resolution
Check if "$values['data']" is set.
$data = unserialize($values['data'], ['allowed_classes' => FALSE]);
if (isset($data['argument']) && $data['argument'] === '') {
$data['argument'] = NULL;
$values['data'] = serialize($data);
}ViewsReferenceItem.php (line 97)
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | viewsreference_undefined_key_3335680_5.patch | 1000 bytes | mmaldonado |
Issue fork viewsreference-3335680
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:
- 8.x-2.x
changes, plain diff MR !25
- 3335680-warning-undefined-array-key-data
changes, plain diff MR !24
Comments
Comment #5
mmaldonado commentedThe same error has happened to me when executing a migration. According to the change that you have proposed iiRealXz, I have uploaded a temporary patch.
Greetings.
Comment #6
seanbA fix for this has been added in #3273497: Passing null to parameter #1 ($data) of type string to unserialize() is deprecated. Could you please check the latest dev version and let me know if this issue has been resolved?
Comment #7
damien laguerre commentedI had the same issue with Drupal 10 and php 8.1.
I confirm that using the dev version solved the issue.
Thanks!
Comment #8
seanbThank you! Let's close this.