function EnabledExtensionsValidator::validate

Validates that no enabled Drupal extensions have been removed.

Parameters

\Drupal\package_manager\Event\PreApplyEvent $event: The event object.

File

core/modules/package_manager/src/Validator/EnabledExtensionsValidator.php, line 40

Class

EnabledExtensionsValidator
Validates no enabled Drupal extensions are removed from the stage directory.

Namespace

Drupal\package_manager\Validator

Code

public function validate(PreApplyEvent $event) : void {
    $active_packages_list = $this->composerInspector
        ->getInstalledPackagesList($this->pathLocator
        ->getProjectRoot());
    $stage_packages_list = $this->composerInspector
        ->getInstalledPackagesList($event->stage
        ->getStageDirectory());
    $extensions_list = $this->moduleHandler
        ->getModuleList() + $this->themeHandler
        ->listInfo();
    foreach ($extensions_list as $extension) {
        $extension_name = $extension->getName();
        $package = $active_packages_list->getPackageByDrupalProjectName($extension_name);
        if ($package && $stage_packages_list->getPackageByDrupalProjectName($extension_name) === NULL) {
            $removed_project_messages[] = t("'@name' @type (provided by <code>@package</code>)", [
                '@name' => $extension_name,
                '@type' => $extension->getType(),
                '@package' => $package->name,
            ]);
        }
    }
    if (!empty($removed_project_messages)) {
        $removed_packages_summary = $this->formatPlural(count($removed_project_messages), 'The update cannot proceed because the following enabled Drupal extension was removed during the update.', 'The update cannot proceed because the following enabled Drupal extensions were removed during the update.');
        $event->addError($removed_project_messages, $removed_packages_summary);
    }
}

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