Fatal when entity type doesn't exist (anymore)

Created on 26 December 2024, 3 months ago

Problem/Motivation

This module includes the following default configuration for enabled entity types, which assumes that the node module is enabled.

enabled_entity_types:
  node: {  }

This isn't validated on install or loading, resulting in the following exception on all pages when the node module isn't enabled.

Drupal\Component\Plugin\Exception\PluginNotFoundException:
The "node" entity type does not exist.

  at /var/www/html/drupal/core/lib/Drupal/Core/Entity/EntityTypeManager.php:139
  at Drupal\Core\Entity\EntityTypeManager->getDefinition()
     (/var/www/html/drupal/modules/contrib/trash/src/Plugin/Derivative/TrashLocalTasks.php:67)
  at Drupal\trash\Plugin\Derivative\TrashLocalTasks->getDerivativeDefinitions()
     (/var/www/html/drupal/core/lib/Drupal/Component/Plugin/Discovery/DerivativeDiscoveryDecorator.php:101)
  at Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDerivatives()
...

This issue will also occur for any entity type that is removed after trash has been enabled for that specific entity type.

Steps to reproduce

- Clean Drupal installation where the node module isn't enabled
- Enable this module

Proposed resolution

We should validate if the entity type actually exists before any logic is applied for the specified entity type. This will resolve the installation issue and will resolve the issue where fatals will occur when an entity type is removed, without mutating the active configuration. In my opinion, the easiest implementation for this is by checking the entity manager for a definition for the specified entity type in TrashManager::getEnabledEntityTypes

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands arkener

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024