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

Issue fork trash-3496091

Command icon 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

arkener created an issue. See original summary.

alexpott made their first commit to this issue’s fork.

alexpott’s picture

Note this also fixes #3496558: Install entity definitions for all modules in batch install before simple config but in a trash specific way. Also it looks as though this exposes some other bug in the module because this change results in test failures.

amateescu made their first commit to this issue’s fork.

alexpott’s picture

Status: Active » Needs work
Related issues: +#3496588: Consider moving router rebuild to after hook_modules_installed

We should add a @todo to remove the rebuild from the test if #3496588: Consider moving router rebuild to after hook_modules_installed lands. Otherwise this looks good to me.

amateescu’s picture

Title: Fatal when entity type doesn't exist (anymore) » Improve the way we enable Trash support by default for nodes
Status: Needs work » Needs review

There's a @todo already in the latest commit from the MR :)

alexpott’s picture

Status: Needs review » Reviewed & tested by the community

todo exists - nice. This looks good to go to me.

  • amateescu committed 08b05299 on 3.x authored by alexpott
    Issue #3496091 by alexpott, amateescu: Improve the way we enable Trash...
amateescu’s picture

Status: Reviewed & tested by the community » Fixed

Merged into 3.x, thanks for all the help here!

amateescu’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.