function DrupalKernel::updateModules

Same name in other branches
  1. 9 core/lib/Drupal/Core/DrupalKernel.php \Drupal\Core\DrupalKernel::updateModules()
  2. 10 core/lib/Drupal/Core/DrupalKernel.php \Drupal\Core\DrupalKernel::updateModules()
  3. 11.x core/lib/Drupal/Core/DrupalKernel.php \Drupal\Core\DrupalKernel::updateModules()

Implements Drupal\Core\DrupalKernelInterface::updateModules().

@todo Remove obsolete $module_list parameter. Only $module_filenames is needed.

Overrides DrupalKernelInterface::updateModules

File

core/lib/Drupal/Core/DrupalKernel.php, line 809

Class

DrupalKernel
The DrupalKernel class is the core of Drupal itself.

Namespace

Drupal\Core

Code

public function updateModules(array $module_list, array $module_filenames = []) {
    $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;
    }
    // If we haven't yet booted, we don't need to do anything: the new module
    // list will take effect when boot() is called. However we set a
    // flag that the container needs a rebuild, so that a potentially cached
    // container is not used. If we have already booted, then rebuild the
    // 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 stored a negative result for a
        // class that is now available.
        // @see \Composer\Autoload\ClassLoader::findFile()
        $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();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.