PHP "Undefined array key" warnings after update

Created on 28 July 2023, over 1 year ago
Updated 21 April 2024, 7 months ago

Problem/Motivation

After upgrading from 8.x-1.0-alpha3 to 2.0.0-alpha1, we starting getting these PHP warnings:

Warning: Undefined array key "sort_bundle_order" in Drupal\entity_reference_exposed_filters\Plugin\views\filter\EREFNodeTitles->generateOptions() (line 379 of /app/web/modules/contrib/entity_reference_exposed_filters/src/Plugin/views/filter/EREFNodeTitles.php)

Warning: Undefined array key "" in Drupal\entity_reference_exposed_filters\Plugin\views\filter\EREFNodeTitles->generateOptions() (line 379 of /app/web/modules/contrib/entity_reference_exposed_filters/src/Plugin/views/filter/EREFNodeTitles.php)

Deprecated function: strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Entity\Query\QueryBase->sort() (line 240 of /app/web/core/lib/Drupal/Core/Entity/Query/QueryBase.php)

The issue is that a new "Sort bundles" setting was added to the Entity Reference Exposed Filters Node Titles filter. Views created with an older version of this module don't have this setting, and there is no default.

Steps to reproduce

  1. Create Drupal View using version 8.x-1.0-alpha3
  2. Upgrade code to version 2.0.0-alpha1
  3. View page that uses the Drupal View

Proposed resolution

The simplest way for a user to fix this is to edit the View, click on the"Settings" link for the filter, set the "Sort bundles" value, apply the changes, and save the view.

The actual solution would be to do one of the following:

  1. Create a hook_update_n() that adds the setting to any View that doesn't have it.
  2. Update the code in EREFNodeTitles::generateOptions() to not throw warnings when the setting option isn't there.
  3. Add a note to the release notes for the 2.0 versions that tells people to go re-save the View per above.

Remaining tasks

Do one of the options above.

Mostly, I just wanted to document this for others that encountered the same issue since it's an easy fix.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇺🇸United States jrb Raleigh-Durham Area, NC, USA

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024