EntityReference ViewsSelection::stripAdminAndAnchorTagsFromResults() should call Element::children($results)

Created on 14 February 2023, almost 2 years ago
Updated 20 September 2023, over 1 year ago

Problem/Motivation

Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection::stripAdminAndAnchorTagsFromResults() causes a fatal Uncaught PHP Exception Error: "Call to a member function bundle() on null if the view $results contain elements which are do not have a ['#row']->_entity property (i.e. an instance of \Drupal\views\ResultRow).

This can happen if the $results render array have a property, e.g. #cache

Steps to reproduce

Create a view with an Entity Reference Selection display
Implement hook_views_post_render, in it alter the $output and add a cache tag, e.g. $output['#cache']['tags'][] = 'workbench_access_view';
Render the view, notice the fatal error

Proposed resolution

Change stripAdminAndAnchorTagsFromResults() looping over the results to use a standard Element::children($results)

Remaining tasks

Review, add tests

User interface changes

NA

API changes

NA

Data model changes

NA

πŸ› Bug report
Status

Fixed

Version

9.5

Component
ViewsΒ  β†’

Last updated 2 days ago

Created by

πŸ‡¦πŸ‡ΊAustralia fenstrat Australia

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

Comments & Activities

Production build 0.71.5 2024