Context
Entity types whose storage is not SQL (External Entities, ContentEntityNullStorage such as contact_message) are allowed by the entity API, but Views, entity reference relationships and entity query mostly assume every content entity type has SQL tables. On PHP 8.5 the assumption started to show: code that used to build Views data under a NULL table name, which PHP silently turned into '', now raises "Using null as an array offset is deprecated".
Found on the contrib site, where the drupal.org issue, module and release history entities are External Entities referenced from nodes and terms:
- Core: View on Drupal.org #3641172ViewsViewsHooks::fieldViewsData() uses NULL as an array key when the reference target has no SQL tables Status: Active,
ViewsViewsHooks::fieldViewsData()keys the reverse reference relationship by the target'sNULLbase table. Fix and kernel tests pushed to the issue fork, branch3641172-viewsviewshooksfieldviewsdata-uses-null. - Registration: View on GitLab #3628463PHP 8.5 deprecation warnings for relationships on entities without base tables Status: Active,
RegistrationViewsHooks::viewsDataAlter()does the same for every fieldable entity type. Contact alone reproduces it. MR !203.
Both are patched locally (patches/drupal-views-field-data-null-base-table.diff, patches/registration-3628463-mr203-3.4.9.diff).
Root issues
1. Table names live in two places that can disagree
The entity type definition stores base_table / data_table, but the SQL storage decides them: DefaultTableMapping falls back to <id> and <id>_field_data when the definition omits them. Code that asks the definition gets NULL for an entity type that has real tables, and the same NULL for one that has none at all, so "no table name" cannot be told apart from "default table name".
- View on Drupal.org #2328565Omitting the "base_table" or "data_table" for entity types is broken Status: Needs work Omitting the "base_table" or "data_table" for entity types is broken. Needs work since 2014. The storage and the definition disagree, and install breaks.
- View on Drupal.org #3174342Omitting the base_table from an entity type works with the storage, but not with queries Status: Active Omitting the base_table works with the storage, but not with queries. Active.
Sql\Querythrows "No base table" where the storage would have used the default. - View on Drupal.org #3572144Operator precedence bug in DefaultTableMapping causes malformed SQL when entity type tables are not configured Status: Needs work Operator precedence bug in
DefaultTableMapping. Needs work. The defaults themselves are wrong when the mapping has a prefix, which only temporary mappings do; blocked on whether an upgrade path is needed. - View on Drupal.org #2958963Provide default values for the table name annotations for content entities Status: Needs work Provide default values for the table name annotations. Needs work since 2019. Would set the defaults on the definition instead; berdir argues
getBaseTable()should not ask the storage. - View on Drupal.org #2960037Add a way to get the primary table of an entity type from TableMappingInterface Status: Needs work Add
TableMappingInterface::getPrimaryTableName(). Needs work since 2023. The replacement API callers like Views should use. - View on Drupal.org #2232465Deprecate table names from entity definitions Status: Postponed (maintainer needs more info) Deprecate table names from entity definitions. Postponed. The end state: table names belong to the storage only.
- View on Drupal.org #3035130DX for translatable entities: Exception when omitting the "data_table" for entity types Status: Needs work Exception when omitting
data_tablefor translatable entity types. Needs work. Error messages only; note its check would also throw for a translatable non-SQL entity type.
2. Views assumes SQL storage
Views data, handlers and the query plugin read entity tables without checking whether the storage has any.
- View on Drupal.org #2079019Make Views use SqlEntityStorageInterface Status: Needs work Make Views use
SqlEntityStorageInterface. Needs work since 2014. Maintainers agreed Views should check for SQL storage and take tables from its table mapping, the approach of the #3641172 fix. - View on Drupal.org #2484565Views is broken with non-Sql query plugins Status: Needs work Views is broken with non-SQL query plugins. Needs work, MR !17323. Handlers call SQL-only methods on any query plugin (Search API).
- View on Drupal.org #3084974Make \Drupal\views\Plugin\views\query\Sql more easy to extend with a small code refactoring Status: Needs work Make the Views
Sqlquery plugin easier to extend. Needs work since 2019. External Entities had to copy all ofSql::query()to load its entities.
3. The PHP 8.5 symptoms, fixed one at a time
Each was fixed with a guard where the code met a NULL table; none addressed the causes above.
- View on Drupal.org #3546535[meta] Deal with NULL as array key/offset Status: Closed (fixed) [meta] Deal with NULL as array key/offset. Closed (fixed).
fieldViewsData()was never one of its children. - View on Drupal.org #3557142\Drupal\views\FieldViewsDataProvider::defaultFieldImplementation creates a join for a non-existing table causing deprecations on PHP 8.5 Status: Closed (fixed) and its follow-up View on Drupal.org #3582171[PHP 8.5] Strengthen views data with entity types w/o data tables Status: Closed (fixed),
FieldViewsDataProvider::defaultFieldImplementation(). Fixed. #3582171 addedEntityWithoutBaseTableTest. - View on Drupal.org #3581679[PHP 8.5] ViewsViewsHooks::viewsData() should not add Bulk Update fields for entity types without base table Status: Needs work
ViewsViewsHooks::viewsData()bulk form fields. Fixed on main by #3347842; 11.4 already skips entity types without a base table, in the same file as #3641172. - View on Drupal.org #3557181\Drupal\content_translation\Hook\ContentTranslationHooks::viewsDataAlter() causes deprecations on PHP 8.5 Status: Closed (fixed)
ContentTranslationHooks::viewsDataAlter()and View on Drupal.org #3557467\Drupal\content_moderation\ViewsData::getViewsData() causes PHP 8.5 deprecations and tries to and moderation_state info for non-existing table Status: Closed (fixed) content_moderationViewsData. Fixed. - View on Drupal.org #3616463Deprecated function: Using null as an array offset is deprecated, use an empty string instead in Drupal\views\FieldViewsDataProvider->defaultFieldImplementation() (line 221 of core/modules/views/src/FieldViewsDataProvider.php). Status: Needs work A remaining deprecation at line 221 of
FieldViewsDataProvider. Open.
References and entity query
- An entity reference field can only target an entity type with an ID key (
EntityReferenceItemthrows "has no ID key and cannot be targeted"), socontact_messagecannot be referenced while External Entities can. Core ships no referenceable entity type without tables, which is why #3641172 needed a test module. - Views relationships to a non-SQL target cannot be made to work in core:
entity_reversejoins SQL tables, and a view of external entities has to usexntt_viewsand its own query plugin. #3641172 drops those relationships; they were never usable. - Entity query on SQL storage reads the definition too (#3174342). View on Drupal.org #2875033Optimize joins and table selection in SQL entity query implementation Status: Closed (fixed) (fixed in 11.4) asked about external entities in comment #39 without an answer.
Further findings
Found in a wider search of drupal.org; status taken from search results, not yet checked on each issue page.
Views
- View on Drupal.org #2349553Store entity field information in the views data Status: Closed (fixed) Store entity field information in the views data. Committed to 8.0.x. Groundwork for handlers not tied to SQL, but the issue itself concedes a generic handler stays coupled to SQL because Views data mirrors tables.
- View on Drupal.org #2983751Does View load entire entity or just the fields required? Status: Closed (fixed) Does View load entire entity or just the fields required? Background on how the
Sqlquery plugin loads entities, relevant to #3084974. - View EntityFieldQuery Views Backend (efq_views) on Drupal.orgEntityFieldQuery Views Backend (efq_views)Covered by the Drupal security advisory policy: the old contrib answer, a Views query plugin built on entity query so non-SQL entities can be listed. Mostly D7; its D8 issues are largely unresolved. Prior art for what
xntt_viewsdoes now.
Entity query
- View on Drupal.org #2389335Deprecate entity.query service and replace with using the entity storage's getQuery() method Status: Closed (fixed) Deprecate the
entity.queryservice in favor of the storage'sgetQuery(). This is what lets a non-SQL storage supply its own query class (External Entities does). - https://www.drupal.org/project/drupal/issues/2909970 (Entity API) Implement a query-level entity access API. Entity query has no alter step below SQL, so query access is only enforced at the SQL level, as in Views. A non-SQL query gets no access filtering from it.
- View on Drupal.org #3188918Allow EntityQuery to be converted to the underlying SQL query Status: Needs work Allow EntityQuery to be converted to the underlying SQL query. SQL-only by nature; shows how much of the query API is SQL-shaped.
- View on Drupal.org #2424791Entity query hardcodes entity_reference and entity specifier Status: Closed (fixed) Entity query hardcodes
entity_referenceand theentityspecifier. Relationship traversal (field.entity.title) is built intoSql\Tables, so a condition across a reference into a non-SQL target cannot work there. - View on Drupal.org #2908605Pass field storage to Tables::addNextBaseField() Status: Closed (fixed) Pass field storage to
Tables::addNextBaseField(). Same area ofSql\Tables. - View on Drupal.org #2554235Make the content entity storage and entity query use the last installed definitions instead of the ones living in code Status: Closed (fixed) Make content entity storage and entity query use the last installed definitions. Another place where the definition and the storage disagree, related to root issue 1.
Entity references
- View on Drupal.org #1801304Add Entity reference field Status: Closed (fixed) Add Entity reference field. The Views selection handler finds views by matching the target's base table, so a non-SQL target has no usable Views selection.
- View on Drupal.org #2577963Let entity_ref Selection handlers be in charge of the field validation Status: Closed (fixed) Let entity reference selection handlers be in charge of field validation. Selection handlers run entity queries, so the default handler works for a non-SQL target only as far as its storage's query does.
- View on Drupal.org #2429699Add Views EntityReference filter to be available for all entity reference fields Status: Closed (duplicate) Add a Views entity reference filter for all entity reference fields. Another Views handler keyed by table.
- View on GitLab #2822359Support "entity" property definition in entity queries using Entity Reference Revisions fields Status: Needs work Support the
entityproperty in entity queries on ERR fields. Contrib running into #2424791. - Dynamic Entity Reference: a support request "Are non-SQL storage based entities supported?" is closed (works as designed), and a patch on View on GitLab #2555027Support non-numeric entity ID's Status: Closed carries the comment "Only SQL storage based entities are supported." DER's 2.x/4.x also use database triggers, so it cannot target non-SQL entities. Link to the support request not found yet; see the issue queue.
Ideas
- Views should check for
SqlEntityStorageInterfaceand take every table name from the table mapping (#2079019), whichgetPrimaryTableName()(#2960037) would reduce to one call. - Contrib modules that build Views data for every entity type should do the same; Registration is one, there are likely others.
- Entity query conditions across a reference (
field.entity.x) should hand off to the target storage's query when it is not SQL, rather than joining tables (#2424791).