You are here

class RequiredModuleUninstallValidator in Zircon Profile 8.0

Same name in this branch
  1. 8.0 core/lib/Drupal/Core/Extension/RequiredModuleUninstallValidator.php \Drupal\Core\Extension\RequiredModuleUninstallValidator
  2. 8.0 core/lib/Drupal/Core/ProxyClass/Extension/RequiredModuleUninstallValidator.php \Drupal\Core\ProxyClass\Extension\RequiredModuleUninstallValidator
Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Extension/RequiredModuleUninstallValidator.php \Drupal\Core\Extension\RequiredModuleUninstallValidator

Ensures that required modules cannot be uninstalled.

Hierarchy

Expanded class hierarchy of RequiredModuleUninstallValidator

1 string reference to 'RequiredModuleUninstallValidator'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses RequiredModuleUninstallValidator
required_module_uninstall_validator in core/core.services.yml
Drupal\Core\Extension\RequiredModuleUninstallValidator

File

core/lib/Drupal/Core/Extension/RequiredModuleUninstallValidator.php, line 16
Contains \Drupal\Core\Extension\RequiredModuleUninstallValidator.

Namespace

Drupal\Core\Extension
View source
class RequiredModuleUninstallValidator implements ModuleUninstallValidatorInterface {
  use StringTranslationTrait;

  /**
   * Constructs a new RequiredModuleUninstallValidator.
   *
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The string translation service.
   */
  public function __construct(TranslationInterface $string_translation) {
    $this->stringTranslation = $string_translation;
  }

  /**
   * {@inheritdoc}
   */
  public function validate($module) {
    $reasons = [];
    $module_info = $this
      ->getModuleInfoByModule($module);
    if (!empty($module_info['required'])) {
      $reasons[] = $this
        ->t('The @module module is required', [
        '@module' => $module_info['name'],
      ]);
    }
    return $reasons;
  }

  /**
   * Returns the module info for a specific module.
   *
   * @param string $module
   *   The name of the module.
   *
   * @return array
   *   The module info, or NULL if that module does not exist.
   */
  protected function getModuleInfoByModule($module) {
    $modules = system_rebuild_module_data();
    return isset($modules[$module]->info) ? $modules[$module]->info : [];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RequiredModuleUninstallValidator::getModuleInfoByModule protected function Returns the module info for a specific module.
RequiredModuleUninstallValidator::validate public function Determines the reasons a module can not be uninstalled. Overrides ModuleUninstallValidatorInterface::validate
RequiredModuleUninstallValidator::__construct public function Constructs a new RequiredModuleUninstallValidator.
StringTranslationTrait::$stringTranslation protected property The string translation service.
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.