Warning: Undefined array key "data"

Created on 23 January 2023, almost 2 years ago
Updated 29 March 2023, over 1 year ago

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

🐛 Bug report
Status

Closed: outdated

Version

2.0

Component

Code

Created by

🇪🇸Spain javier_rey

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024