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

  1. Install the module.
  2. Structure » Content types » Basic page » Manage fields » Add views reference field
  3. Configure the field (in my case, block and checked some "Preselect View Options")
  4. Create a new basic page content
  5. 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

Command icon 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

iiRealXz created an issue. See original summary.

mmaldonado’s picture

StatusFileSize
new1000 bytes

The 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.

seanb’s picture

A 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?

damien laguerre’s picture

I had the same issue with Drupal 10 and php 8.1.
I confirm that using the dev version solved the issue.

Thanks!

seanb’s picture

Status: Active » Closed (outdated)

Thank you! Let's close this.