Custom entity type does not exist. Admin toobar tools derived links error

Created on 26 August 2025, about 1 month ago

Problem/Motivation

After uninstalling a custom entity-type module, the Admin Toolbar (admin_toolbar_tools) crashes. A derived menu link plugin still references the now-missing entity type and causes a fatal when the toolbar renders.

Steps to reproduce

  1. Enable admin_toolbar and admin_toolbar_tools.
  2. Enable a module that defines a custom entity type (e.g., resource_type).
  3. Uninstall that custom entity-type module.
  4. Load an admin page.

Expected result

  • No fatal errors; toolbar renders. Any derived menu links for the removed entity type are removed/ignored.

Actual result

The website encountered an unexpected error. Try again later.

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "resource_type" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 142 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).

Drupal\Core\Entity\EntityTypeManager->getHandler() (Line: 195)
Drupal\Core\Entity\EntityTypeManager->getStorage() (Line: 38)
Drupal\admin_toolbar_tools\Plugin\Menu\MenuLinkEntity::create() (Line: 21)
Drupal\Core\Plugin\Factory\ContainerFactory->createInstance() (Line: 194)
Drupal\Core\Menu\MenuLinkManager->createInstance() (Line: 130)
Drupal\Core\Menu\MenuLinkTree->createInstances() (Line: 125)
Drupal\Core\Menu\MenuLinkTree->createInstances() (Line: 107)
Drupal\Core\Menu\MenuLinkTree->load() (Line: 118)
Drupal\toolbar\Controller\ToolbarController::preRenderGetRenderedSubtrees()
call_user_func_array() (Line: 113)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 886)
Drupal\Core\Render\Renderer->doCallback() (Line: 431)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 283)
{closure}() (Line: 637)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 282)
toolbar_get_rendered_subtrees() (Line: 295)
_toolbar_get_subtrees_hash() (Line: 168)
toolbar_toolbar()
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 191)
Drupal\toolbar\Element\Toolbar::preRenderToolbar()
... omitted for brevity ...

Proposed resolution

  • In admin_toolbar_tools, guard against missing entity types. In the deriver and/or in Plugin\Menu\MenuLinkEntity::create(), check entity_type.manager->hasDefinition($entity_type_id) before calling getStorage(); skip creating the plugin if not found.
  • Additionally, on module uninstall, trigger a rebuild of menu link plugins to drop stale derived definitions:
    \Drupal::service('plugin.manager.menu.link')->rebuild();
  • Make the deriver resilient to mid-request removals (catch PluginNotFoundException and return no derivatives).
  • Add a test that enables a custom entity type, uninstalls it, then loads an admin route to ensure no fatal occurs.
🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇨🇦Canada joelpittet Vancouver

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

Comments & Activities

Production build 0.71.5 2024