Problem/Motivation
The Custom Elements views style plugin crashes with a TypeError when a view result row has a null entity ($row->_entity === null). This can happen when an entity is deleted between the view query execution and entity rendering, e.g. during concurrent requests or cache race conditions.
TypeError: Drupal\custom_elements\CustomElementGenerator::generate(): Argument #1 ($entity) must be of type Drupal\Core\Entity\ContentEntityInterface, null given, called in lupus_decoupled_views/src/Plugin/views/style/CustomElements.php on line 86
Steps to reproduce
1. Create a view using the Custom Elements style with an entity row plugin
2. Have content that gets deleted or becomes unavailable between query and render time (e.g. via concurrent requests, cron, or automated test cleanup)
3. The view crashes instead of gracefully skipping the missing entity
This is hard to reproduce manually but occurs in automated testing environments where multiple operations happen in quick succession.
Proposed resolution
Add a null guard for $row->_entity in CustomElements::render() before passing it to CustomElementGenerator::generate(). Rows with null entities should be silently skipped, consistent with how Drupal core handles missing entities in views rendering.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3574300.patch | 867 bytes | petar_basic |
Issue fork lupus_decoupled-3574300
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
Comment #3
petar_basic commentedAdded a check to skip rows where $row->_entity is null in CustomElements::render(). When an entity can't be loaded (e.g. deleted between query and render), the row is now silently skipped instead of crashing with a TypeError. MR is up, patch attached (for use with composer patches).
Comment #5
fagothx, straight-forward fix. Merged.