Exception thrown on usage page if an inline content block is a source usage but the parent layout builder entity was moved to the trash (via Trash module)

Created on 23 May 2025, about 2 months ago

Problem/Motivation

For sites using the Trash module, entities can be moved to the trash which means they're soft deleted. The module sets a flag on the entity indicating it's deleted, and it's permanently deleted at a later date when the trash is purged. The module does some trickery to have the entity storage managers return NULL when you try to load an entity that's in the trash.

Let's say you have this scenario:

Layout Builder Entity > Inline Content Block > Tracked Target Entity

Normally when you view usage of the Tracked Target Entity, it will show the Inline Content Block as a source usage as expected.

When Entity Usage tries to show the usage report of source entities for a given target entity, it checks if the user has access to view the label of the source entity. For inline blocks, access is deferred to the parent layout builder entity that uses it. But this causes an exception if that layout builder entity is in the trash, as it won't appear to exist. Here's the stack trace:

TypeError: Drupal\layout_builder\EventSubscriber\SetInlineBlockDependency::isLayoutCompatibleEntity(): Argument #1 ($entity) must be of type Drupal\Core\Entity\EntityInterface, null given, called in docroot/core/modules/layout_builder/src/EventSubscriber/SetInlineBlockDependency.php on line 134 in Drupal\layout_builder\EventSubscriber\SetInlineBlockDependency->isLayoutCompatibleEntity() (line 36 of core/modules/layout_builder/src/LayoutEntityHelperTrait.php).

Drupal\layout_builder\EventSubscriber\SetInlineBlockDependency->getInlineBlockDependency(Object) (Line: 95)
Drupal\layout_builder\EventSubscriber\SetInlineBlockDependency->onGetDependency(Object, 'block_content.get_dependency', Object)
call_user_func(Array, Object, 'block_content.get_dependency', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'block_content.get_dependency') (Line: 92)
Drupal\block_content\BlockContentAccessControlHandler->checkAccess(Object, 'view', Object) (Line: 109)
Drupal\Core\Entity\EntityAccessControlHandler->access(Object, 'view', Object, ) (Line: 739)
Drupal\Core\Entity\ContentEntityBase->access('view label') (Line: 490)
Drupal\entity_usage\Controller\ListUsageController->getSourceEntityLink(Object) (Line: 300)
Drupal\entity_usage\Controller\ListUsageController->getRows('media', '1') (Line: 158)
Drupal\entity_usage\Controller\ListUsageController->listUsagePage('media', '1') (Line: 54)

I suppose there's a few different ways this could be solved, but ultimately I don't think we should be attempting to show inline blocks as sources if their parent has been deleted (soft deleted via trash or permanently deleted).

This problem is closely related to πŸ› Exception thrown on usage page if a layout builder block has usage but its parent entity was deleted Active , but this handles the scenario with the parent layout builder entity has been "soft" deleted via the Trash module.

Steps to reproduce

Proposed resolution

On the entity usage page, if the source is an inline (non-reusable) content block entity, check if its parent is in the trash. If so, don't show it.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

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

Comments & Activities

Production build 0.71.5 2024