Problem/Motivation

When editing a paragraph type, an error related to Entity Usage appeared, so attempting to uninstall the module also resulted in an error.

The website encountered an unexpected error. Try again later.

Error: Call to a member function getEntityTypeId() on null in Drupal\entity_usage\Controller\LocalTaskUsageController->checkAccessLocalTask() (line 26 of modules/contrib/entity_usage/src/Controller/LocalTaskUsageController.php).
call_user_func_array() (Line: 66)
Drupal\Core\Access\CustomAccessCheck->access()
call_user_func_array() (Line: 160)
Drupal\Core\Access\AccessManager->performCheck() (Line: 136)
Drupal\Core\Access\AccessManager->check() (Line: 93)
Drupal\Core\Access\AccessManager->checkNamedRoute() (Line: 328)
Drupal\Core\Menu\LocalTaskManager->getTasksBuild() (Line: 359)
Drupal\Core\Menu\LocalTaskManager->getLocalTasks() (Line: 83)
Drupal\admin_toolbar_tools\AdminToolbarToolsHelper->buildLocalTasksToolbar() (Line: 29)
admin_toolbar_tools_toolbar()
call_user_func_array() (Line: 404)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 357)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 403)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 77)
Drupal\toolbar\Element\Toolbar::preRenderToolbar()
call_user_func_array() (Line: 107)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 876)
Drupal\Core\Render\Renderer->doCallback() (Line: 438)
Drupal\Core\Render\Renderer->doRender() (Line: 510)
Drupal\Core\Render\Renderer->doRender() (Line: 227)
Drupal\Core\Render\Renderer->render() (Line: 491)
Drupal\Core\Template\TwigExtension->escapeFilter() (Line: 88)
__TwigTemplate_8ee167124604d54e54f11d6dc8c524c2->doDisplay() (Line: 402)
Twig\Template->yield() (Line: 358)
Twig\Template->display() (Line: 373)
Twig\Template->render() (Line: 51)
Twig\TemplateWrapper->render() (Line: 34)
twig_render_template() (Line: 380)
Drupal\Core\Theme\ThemeManager->render() (Line: 497)
Drupal\Core\Render\Renderer->doRender() (Line: 227)
Drupal\Core\Render\Renderer->render() (Line: 162)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 157)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray() (Line: 246)
Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}() (Line: 206)
Symfony\Component\EventDispatcher\EventDispatcher->callListeners() (Line: 56)
Symfony\Component\EventDispatcher\EventDispatcher->dispatch() (Line: 188)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 53)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 715)
Drupal\Core\DrupalKernel->handle() (Line: 19)

The Entity Usage module depends on the Paragraph library and Paragraphs Demo modules.
Uninstalling Paragraphs Demo followed by Paragraph library succeeded without error.
However, the following error ultimately appeared, preventing the uninstallation of Entity Usage.

The website encountered an unexpected error. Try again later.

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "paragraphs_library_item" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 139 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).
entity_usage_module_preuninstall()
call_user_func_array() (Line: 404)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 357)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 403)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 568)
Drupal\Core\Extension\ModuleInstaller->uninstall() (Line: 91)
Drupal\Core\ProxyClass\Extension\ModuleInstaller->uninstall() (Line: 182)
Drupal\system\Form\ModulesUninstallConfirmForm->submitForm()
call_user_func_array() (Line: 105)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() (Line: 43)
Drupal\Core\Form\FormSubmitter->doSubmitForm() (Line: 589)
Drupal\Core\Form\FormBuilder->processForm() (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 53)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 715)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Environment:
Drupal core 11.2.9
Paragraph 8.x-1.19
PHP 8.48.3.27

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

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

s-jack created an issue. See original summary.

s-jack’s picture

Issue summary: View changes
s-jack’s picture

As a Sunday programmer, I relied on Google Antigravity for a solution and successfully uninstalled it.
I've attached the workthrough for reference.

Entity Usage Uninstall Fix Walkthrough
Summary
The entity_usage module failed to uninstall due to a PluginNotFoundException caused by attempting to load definitions for entity types from already uninstalled modules (specifically paragraphs_library_item).
I patched entity_usage.module to check for the existence of an entity type definition before attempting to retrieve it during the uninstall process.

Changes
Fixed entity_usage_module_preuninstall
In web/modules/contrib/entity_usage/entity_usage.module, I added a check using EntityTypeManager::hasDefinition properly handle missing entity types.

foreach ($source_entity_types as $key => $entity_type_id) {
    // Added check:
    if (!$entity_type_manager->hasDefinition($entity_type_id)) {
      unset($source_entity_types[$key]);
      continue;
    }
    // ...
    $entity_type = $entity_type_manager->getDefinition($entity_type_id);

Verification
I verified the fix by successfully running the uninstall command:

ddev drush pm:uninstall entity_usage -y
Result: [success] Successfully uninstalled: entity_usage

The module has been successfully uninstalled.

alexpott’s picture

Version: 8.x-2.0-beta25 » 8.x-2.x-dev

alexpott’s picture

Status: Active » Needs review

Thanks for the bug report. I can see that we should harden this code. Taken a slightly different approach from AI but the result is the same.

alexpott’s picture

Title: Uninstall is not possible » Uninstall is not possible when entity type goes missing

  • alexpott committed c2b763e4 on 5.x
    fix: #3561876 Uninstall is not possible when entity type goes missing...

  • alexpott committed 7ea09798 on 8.x-2.x
    fix: #3561876 Uninstall is not possible when entity type goes missing...
alexpott’s picture

Status: Needs review » Fixed

Going to merge this one as it is a simple hardening.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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