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
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 #4
alexpottNote 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.
Comment #6
alexpottWe 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.
Comment #7
amateescu commentedThere's a @todo already in the latest commit from the MR :)
Comment #8
alexpotttodo exists - nice. This looks good to go to me.
Comment #10
amateescu commentedMerged into 3.x, thanks for all the help here!
Comment #11
amateescu commentedOpened #3496616: Clean up trash-enabled entity types when they're uninstalled to handle the uninstall part of this problem.