function InstallProfileUninstallValidator::validate

Same name in this branch
  1. 10 core/lib/Drupal/Core/ProxyClass/Extension/InstallProfileUninstallValidator.php \Drupal\Core\ProxyClass\Extension\InstallProfileUninstallValidator::validate()
Same name in other branches
  1. 11.x core/lib/Drupal/Core/ProxyClass/Extension/InstallProfileUninstallValidator.php \Drupal\Core\ProxyClass\Extension\InstallProfileUninstallValidator::validate()
  2. 11.x core/lib/Drupal/Core/Extension/InstallProfileUninstallValidator.php \Drupal\Core\Extension\InstallProfileUninstallValidator::validate()

Overrides ModuleUninstallValidatorInterface::validate

File

core/lib/Drupal/Core/Extension/InstallProfileUninstallValidator.php, line 38

Class

InstallProfileUninstallValidator
Ensures install profile can only be uninstalled if the modules are available.

Namespace

Drupal\Core\Extension

Code

public function validate($module) : array {
    $reasons = [];
    // When there are modules installed that only exist in the install profile's
    // directory an install profile can not be uninstalled.
    if ($module === $this->installProfile) {
        $profile_name = $this->moduleExtensionList
            ->get($module)->info['name'];
        $profile_only_modules = array_diff_key($this->moduleExtensionList
            ->getAllInstalledInfo(), $this->getExtensionDiscovery()
            ->scan('module'));
        // Remove the install profile as we're uninstalling it.
        unset($profile_only_modules[$module]);
        if (!empty($profile_only_modules)) {
            $reasons[] = $this->t("The install profile '@profile_name' is providing the following module(s): @profile_modules", [
                '@profile_name' => $profile_name,
                '@profile_modules' => implode(', ', array_keys($profile_only_modules)),
            ]);
        }
        $profile_only_themes = array_diff_key($this->themeExtensionList
            ->getAllInstalledInfo(), $this->getExtensionDiscovery()
            ->scan('theme'));
        if (!empty($profile_only_themes)) {
            $reasons[] = $this->t("The install profile '@profile_name' is providing the following theme(s): @profile_themes", [
                '@profile_name' => $profile_name,
                '@profile_themes' => implode(', ', array_keys($profile_only_themes)),
            ]);
        }
    }
    elseif (!empty($this->installProfile)) {
        $extension = $this->moduleExtensionList
            ->get($module);
        // Ensure that the install profile does not depend on the module being
        // uninstalled.
        if (isset($extension->required_by[$this->installProfile])) {
            $profile_name = $this->moduleExtensionList
                ->get($this->installProfile)->info['name'];
            $reasons[] = $this->t("The '@profile_name' install profile requires '@module_name'", [
                '@profile_name' => $profile_name,
                '@module_name' => $extension->info['name'],
            ]);
        }
    }
    return $reasons;
}

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