diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index a132ff1..0c970e0 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -2,6 +2,7 @@ namespace Drupal\Core; +use Composer\Autoload\ClassLoader; use Drupal\Component\Assertion\Handle; use Drupal\Component\FileCache\FileCacheFactory; use Drupal\Component\Utility\Unicode; @@ -756,6 +757,10 @@ protected function moduleData($module) { * needed. */ public function updateModules(array $module_list, array $module_filenames = array()) { + $pre_existing_module_namespaces = []; + if ($this->booted && is_array($this->moduleList)) { + $pre_existing_module_namespaces = $this->getModuleNamespacesPsr4($this->getModuleFileNames()); + } $this->moduleList = $module_list; foreach ($module_filenames as $name => $extension) { $this->moduleData[$name] = $extension; @@ -768,6 +773,18 @@ public function updateModules(array $module_list, array $module_filenames = arra // container in order to refresh the serviceProvider list and container. $this->containerNeedsRebuild = TRUE; if ($this->booted) { + // We need to register any new namespaces to a new class loader because + // the current class loader might have negative caches. + $new_namespaces = array_diff_key( + $this->getModuleNamespacesPsr4($this->getModuleFileNames()), + $pre_existing_module_namespaces + ); + if (!empty($new_namespaces)) { + $additional_class_loader = new ClassLoader(); + $this->classLoaderAddMultiplePsr4($new_namespaces, $additional_class_loader); + $additional_class_loader->register(); + } + $this->initializeContainer(); } } @@ -1383,7 +1400,10 @@ protected function getModuleNamespacesPsr4($module_file_names) { * is either a PSR-4 base directory, or an array of PSR-4 base directories * associated with this namespace. */ - protected function classLoaderAddMultiplePsr4(array $namespaces = array()) { + protected function classLoaderAddMultiplePsr4(array $namespaces = array(), $classloader = NULL) { + if ($classloader === NULL) { + $classloader = $this->classLoader; + } foreach ($namespaces as $prefix => $paths) { if (is_array($paths)) { foreach ($paths as $key => $value) { @@ -1393,7 +1413,7 @@ protected function classLoaderAddMultiplePsr4(array $namespaces = array()) { elseif (is_string($paths)) { $paths = $this->root . '/' . $paths; } - $this->classLoader->addPsr4($prefix . '\\', $paths); + $classloader->addPsr4($prefix . '\\', $paths); } } diff --git a/core/modules/content_translation/src/ContentTranslationUpdatesManager.php b/core/modules/content_translation/src/ContentTranslationUpdatesManager.php index 6065c18..4fa54f3 100644 --- a/core/modules/content_translation/src/ContentTranslationUpdatesManager.php +++ b/core/modules/content_translation/src/ContentTranslationUpdatesManager.php @@ -95,7 +95,7 @@ public function onMigrateImport(MigrateImportEvent $event) { */ public static function getSubscribedEvents() { $events[ConfigEvents::IMPORT][] = ['onConfigImporterImport', 60]; - if (\Drupal::moduleHandler()->moduleExists('migrate')) { + if (class_exists('\Drupal\migrate\Event\MigrateEvents')) { $events[MigrateEvents::POST_IMPORT][] = ['onMigrateImport']; } return $events;