function UpdateRegistry::onConfigSave

Same name in other branches
  1. 10 core/lib/Drupal/Core/Update/UpdateRegistry.php \Drupal\Core\Update\UpdateRegistry::onConfigSave()
  2. 11.x core/lib/Drupal/Core/Update/UpdateRegistry.php \Drupal\Core\Update\UpdateRegistry::onConfigSave()

Processes the list of installed extensions when core.extension changes.

Parameters

\Drupal\Core\Config\ConfigCrudEvent $event: The Event to process.

File

core/lib/Drupal/Core/Update/UpdateRegistry.php, line 346

Class

UpdateRegistry
Provides all and missing update implementations.

Namespace

Drupal\Core\Update

Code

public function onConfigSave(ConfigCrudEvent $event) {
    $config = $event->getConfig();
    if ($config->getName() === 'core.extension') {
        // Build the old extension configuration list from configuration rather
        // than using $this->enabledExtensions. This ensures that if the
        // UpdateRegistry is constructed after _drupal_maintenance_theme() has
        // added a theme to the theme handler it will not be considered as already
        // installed.
        $old_extension_list = array_keys($config->getOriginal('module') ?? []);
        $new_extension_list = array_keys($config->get('module'));
        if ($this->includeThemes()) {
            $new_extension_list = array_merge($new_extension_list, array_keys($config->get('theme')));
            $old_extension_list = array_merge($old_extension_list, array_keys($config->getOriginal('theme') ?? []));
        }
        // The list of extensions installed or uninstalled. In regular operation
        // only one of the lists will have a single value. This is because Drupal
        // can only install one extension at a time.
        $uninstalled_extensions = array_diff($old_extension_list, $new_extension_list);
        $installed_extensions = array_diff($new_extension_list, $old_extension_list);
        // Set the list of enabled extensions correctly so update function
        // discovery works as expected.
        $this->enabledExtensions = $new_extension_list;
        foreach ($uninstalled_extensions as $uninstalled_extension) {
            $this->filterOutInvokedUpdatesByExtension($uninstalled_extension);
        }
        foreach ($installed_extensions as $installed_extension) {
            // Ensure that all post_update functions are registered already. This
            // should include existing post-updates, as well as any specified as
            // having been previously removed, to ensure that newly installed and
            // updated sites have the same entries in the registry.
            $this->registerInvokedUpdates(array_merge($this->getUpdateFunctions($installed_extension), array_keys($this->getRemovedPostUpdates($installed_extension))));
        }
    }
}

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