Error thrown when entity is not found

Created on 24 January 2025, 29 days ago

Problem/Motivation

I am getting the following error when I use Drupal\entity_usage\EntityUsage->listSources().
The website encountered an unexpected error. Try again later.<br><br><em class="placeholder">TypeError</em>: Drupal\entity_usage\EntityUsage::getSourceEntityLink(): Argument #1 ($source_entity) must be of type Drupal\Core\Entity\EntityInterface, null given, called in /var/www/html/docroot/modules/contrib/entity_usage/src/EntityUsage.php on line 268 in <em class="placeholder">Drupal\entity_usage\EntityUsage-&gt;getSourceEntityLink()</em> (line <em class="placeholder">416</em> of <em class="placeholder">modules/contrib/entity_usage/src/EntityUsage.php</em>). <pre class="backtrace">Drupal\entity_usage\EntityUsage-&gt;listSources(Object) (Line: 56)

I noticed that in the listSources() method, the source entity id was found by the query but when it tries to fetch sourse entity itself, the source entity is NULL.
$source_entity = $type_storage->load($usage->source_id);

Steps to reproduce

Proposed resolution

Add a check to confirm the entity is an instance of EntityInterface before creating source entity link.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Component

Code

Created by

🇮🇳India sushyl@gmail.com Pune

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

Comments & Activities

Production build 0.71.5 2024