PluginNotFoundException: The "taxonomy_term" entity type does not exist.

Created on 24 January 2023, over 1 year ago
Updated 3 May 2024, about 2 months ago

Problem/Motivation

When enabling Webform Views Integration on a site that does NOT have Taxonomy enabled the following error occurs:

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "taxonomy_term" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 139 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).
Drupal\webform_views\WebformElementViews\WebformEntityReferenceViews->getTargetEntityType(Object, Array) (Line: 78)
Drupal\webform_views\WebformElementViews\WebformEntityReferenceViews->getElementViewsData(Object, Array) (Line: 89)
Drupal\webform_views\WebformElementViews\WebformElementViewsAbstract->getViewsData(Array, Object) (Line: 42)
Drupal\webform_views\WebformElementViews\WebformEntityReferenceViews->getViewsData(Array, Object) (Line: 247)
Drupal\webform_views\WebformSubmissionViewsData->getWebformElementViewsData(Array, Object) (Line: 216)
Drupal\webform_views\WebformSubmissionViewsData->getViewsData() (Line: 180)
views_views_data() (Line: 236)
Drupal\views\ViewsData->Drupal\views\{closure}(Object, 'views') (Line: 405)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('views_data', Object) (Line: 244)
Drupal\views\ViewsData->getData() (Line: 154)
Drupal\views\ViewsData->get('node_field_data') (Line: 993)
Drupal\views\ViewExecutable->getBaseEntityType() (Line: 214)
webform_views_applicable_views() (Line: 42)
Drupal\webform_views\Routing\RouteSubscriber->alterRoutes(Object) (Line: 37)
Drupal\Core\Routing\RouteSubscriberBase->onAlterRoutes(Object, 'routing.route_alter', Object)
call_user_func(Array, Object, 'routing.route_alter', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'routing.route_alter') (Line: 189)
Drupal\Core\Routing\RouteBuilder->rebuild() (Line: 83)
Drupal\Core\ProxyClass\Routing\RouteBuilder->rebuild() (Line: 377)
Drupal\Core\Extension\ModuleInstaller->install(Array, 1) (Line: 83)
Drupal\Core\ProxyClass\Extension\ModuleInstaller->install(Array) (Line: 502)
Drupal\system\Form\ModulesListForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 592)
Drupal\Core\Form\FormBuilder->processForm('system_modules', Array, Object) (Line: 320)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

  • Install Drupal
  • Ensure Taxonomy is NOT enabled
  • Attempt to enable Webform Views Integration
  • Observe an error

Proposed resolution

In WebformEntityReferenceViews.php the method getTargetEntityType() attempts to load the entity definition for the given entity type id. At some point the entity type id taxonomy_term is discovered through the entity autocomplete widget which allows taxonomy terms to be referenced.

Ideally, taxonomy_term is never passed into getTargetEntityType() but I don't know enough about this module to know if that's possible. I'm really just trying to evaluate this module for a project. For my purposes I just wrapped the logic into a try/catch like this:

protected function getTargetEntityType(WebformElementEntityReferenceInterface $element_plugin, array $element) {
    try {
      $definition = $this->entityTypeManager->getDefinition($element_plugin->getTargetType($element));
    } catch (PluginNotFoundException $e) {
    }

    return $definition ?? NULL;
  }

I leave it to the those who better understand how this class should work to determine if this is the right approach.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

5.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jeremyr

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024