Problem/Motivation

I'm unsure how I got this, but attempting to uninstall the Modeler API module, it's possible to get a `null` passed into the entityTypeBuild() function.

Steps to reproduce

  1. Drupal CMS latest
  2. Uninstall all dependencies of the Modeler API
  3. Uninstall Modeler API
  4. Get a PHP error
Error: Call to a member function setListBuilderClass() on null in /modeler_api/src/Hook/EntityHooks.php on line 70 #0 /web/core/lib/Drupal/Core/Entity/EntityTypeManager.php(118): Drupal\modeler_api\Hook\EntityHooks->entityTypeBuild()
#1 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(340): Drupal\Core\Entity\EntityTypeManager->Drupal\Core\Entity\{closure}()
#2 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityTypeManager.php(117): Drupal\Core\Extension\ModuleHandler->invokeAllWith()
#3 /var/www/html/web/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php(216): Drupal\Core\Entity\EntityTypeManager->findDefinitions()
#4 /var/www/html/web/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryCachedTrait.php(25): Drupal\Core\Plugin\DefaultPluginManager->getDefinitions()
#5 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityTypeManager.php(132): Drupal\Core\Plugin\DefaultPluginManager->getDefinition()
#6 /var/www/html/web/modules/contrib/eca/src/PluginManager/Action.php(100): Drupal\Core\Entity\EntityTypeManager->getDefinition()
#7 /var/www/html/web/core/lib/Drupal/Core/Action/ActionManager.php(38): Drupal\eca\PluginManager\Action->setCacheBackend()
#8 /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php(259): Drupal\Core\Action\ActionManager->__construct()
#9 /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService()

Proposed resolution

Check to make sure the $type exists before running that block.

Remaining tasks

Review and merge.

User interface changes

None

API changes

None

Data model changes

None

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

robloach created an issue. See original summary.

robloach’s picture

Assigned: robloach » Unassigned
Status: Active » Needs review
jurgenhaas’s picture

Thanks @robloach for reporting this. I'm not sure, though, if the MR is really fixing that issue. This is because the code block looks like this:

      $type = $owner->configEntityTypeId();
      /**
       * @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types
       */
      $entity_types[$type]
        ->setAccessClass(AccessControlHandler::class)
        ->setListBuilderClass(ListBuilder::class)
        ->setLinkTemplate('collection', '/' . $basePath)

The error occurred at ->setListBuilderClass(ListBuilder::class) according to your stack trace which means that ->setAccessClass(AccessControlHandler::class) must have returned NULL, but $entity_types[$type] must have been available, otherwise the previous method call would have had to fail too.

This is strange too because of the function declaration of \Drupal\Core\Entity\EntityTypeInterface::setAccessClass shouldn't return NULL at all. Is this one of those problems that happen with uninstalling modules, something that should be necessary in real life?

jurgenhaas’s picture

Category: Bug report » Task
Status: Needs review » Needs work

Waiting for feedback, setting to NW in the meantime.

kristen pol’s picture

I just ran into this when trying to uninstall 1.2.8. But after running drush un ai again, it worked.

  AI                    AI Core (ai)                                                                          Enabled    1.2.8     
  AI Providers          DropAI Provider (dropai_provider)                                                     Disabled   1.2.8     
  AI                    AI API Explorer (ai_api_explorer)                                                     Disabled   1.2.8     
  AI Tools              AI Assistant API (ai_assistant_api)                                                   Disabled   1.2.8     
  AI                    AI Automators (ai_automators)                                                         Disabled   1.2.8     
  AI Tools              AI Chatbot (ai_chatbot)                                                               Disabled   1.2.8     
  AI                    AI CKEditor integration (ai_ckeditor)                                                 Disabled   1.2.8     
  AI                    AI Content Suggestions (ai_content_suggestions)                                       Disabled   1.2.8     
  AI                    AI ECA integration (ai_eca)                                                           Disabled   1.2.8     
  AI                    AI External Moderation (Deprecated) (ai_external_moderation)                          Disabled   1.2.8     
  AI                    AI Logging (ai_logging)                                                               Disabled   1.2.8     
  AI                    AI Observability (ai_observability)                                                   Disabled   1.2.8     
  AI (Experimental)     AI Search (ai_search)                                                                 Disabled   1.2.8     
  AI                    AI Translate (ai_translate)                                                           Disabled   1.2.8     
  AI                    AI Validations (ai_validations)                                                       Disabled   1.2.8     
  AI Tools              AI Agents (ai_agents)                                                                 Enabled    1.2.1     
  AI Tools              AI Agents Explorer (ai_agents_explorer)                                               Disabled   1.2.1     
  AI Tools              AI Agents Extra (ai_agents_extra)                                                     Disabled   1.2.1     
  AI Tools              AI Agents Extra Tools (ai_agents_extra_tools)                                         Disabled   1.2.1     
  AI Tools              AI Agents Form Integration (ai_agents_form_integration)                               Disabled   1.2.1     
jurgenhaas’s picture

@kristen pol do you have a stack trace? The originally posted stack trace raised my questions in #4 and I wonder how that looked in your scenario.

jurgenhaas’s picture

Status: Needs work » Postponed (maintainer needs more info)
kristen pol’s picture

Hmm. This was so long ago 😅 I probably don’t have that set up anymore. Moving fast and breaking things these days!

robloach’s picture

It's likely from uninstalling a set of modules that were uninstalled in an unexpected order? I do not recall how I was able to get this error, but the safe-guards prevented the error from occurring.

  • jurgenhaas committed e5646041 on 1.1.x authored by robloach
    fix: #3570177 Error: Call to a member function setAccessClass() on null...

  • jurgenhaas committed f4ee5d76 on 1.0.x
    fix: #3570177 Error: Call to a member function setAccessClass() on null...
jurgenhaas’s picture

Status: Postponed (maintainer needs more info) » Fixed

OK, I've now merged and backported this, as the safeguard doesn't hurt.

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.

jurgenhaas’s picture

Status: Fixed » Closed (fixed)