AI disclosure

Used AI to diagnose the issue and draft the fix.

Problem/Motivation

ViewsViewsHooks::fieldViewsData() adds a relationship and a reverse relationship for every entity reference field. It takes the target's table from the entity type definition. EntityTypeInterface::getBaseTable() may return NULL.

When the target entity type has non-SQL storage (External Entities, for example), the reverse relationship is keyed by NULL, which PHP 8.5 reports on every views data rebuild:

Deprecated function: Using null as an array offset is deprecated, use an empty string instead in Drupal\views\Hook\ViewsViewsHooks->fieldViewsData() (line 244 of core/modules/views/src/Hook/ViewsViewsHooks.php).

Before PHP 8.5 the key silently became '', and the forward relationship got 'base' => NULL. Neither is working, but failed silently.

This is the same class of bug as #3557142: \Drupal\views\FieldViewsDataProvider::defaultFieldImplementation creates a join for a non-existing table causing deprecations on PHP 8.5, its follow-up #3582171: [PHP 8.5] Strengthen views data with entity types w/o data tables, and #3546535: [meta] Deal with NULL as array key/offset.

Steps to reproduce

With External Entities 3.x, on PHP 8.5:

  1. Install the Standard profile and enable external_entities.
  2. Add an external entity type, with any storage client.
  3. Add an entity reference field to Article that targets it.
  4. Set "Error messages to display" to "All messages", clear all caches, and load /admin/content.

The deprecation above is shown.

Proposed resolution

Build $target_base_table from SqlEntityStorage->getTableMapping() or getDataTable()/getBaseTable() if using DefaultTableMapping.

Remaining tasks

  • MR
  • Kernel tests

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork drupal-3641172

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

mortona2k created an issue.