Error thrown when programmatically installing project_browser module

Created on 6 July 2023, 12 months ago
Updated 17 June 2024, 9 days ago

Problem/Motivation

If you try to install project_browser module as part of a hook_update_N or hook_post_update_NAME the following error is thrown:

[error] Error: Class "Drupal\project_browser\Event\ProjectBrowserEvents" not found in Drupal\project_browser\EventSubscriber\UpdateFixtureSubscriber::getSubscribedEvents() (line 29 of /var/www/html/docroot/modules/contrib/project_browser/src/EventSubscriber/UpdateFixtureSubscriber.php) #0 /var/www/html/docroot/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php(37): Drupal\project_browser\EventSubscriber\UpdateFixtureSubscriber::getSubscribedEvents()

This seems to boil down to the fact that project_browser uses event class constants for event names and subscribes to it's own dispatched event, which causes this fatal error 🐛 Event class constants for event names can cause fatal errors when a module is installed Active .

Adding drupal_flush_all_caches() before or after installing the module makes no difference.

Steps to reproduce

Add the following code in your_module.install and run drush updb:

function my_module_update_10001(&$sandbox) {
  \Drupal::service('module_installer')->install(['project_browser']);
  drupal_flush_all_caches();
}

Proposed resolution

The underlying issue points out a few workarounds, such us hardcoding the event name in string instead of using constants, or using class_exists() to check if it's available.

🐛 Bug report
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

🇪🇸Spain bmunslow

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