You are here

class RoleAssignUninstallValidator in RoleAssign 8

Same name in this branch
  1. 8 src/RoleAssignUninstallValidator.php \Drupal\roleassign\RoleAssignUninstallValidator
  2. 8 src/ProxyClass/RoleAssignUninstallValidator.php \Drupal\roleassign\ProxyClass\RoleAssignUninstallValidator

Prevents uninstallation of roleassign module by restricted users.

Hierarchy

Expanded class hierarchy of RoleAssignUninstallValidator

1 string reference to 'RoleAssignUninstallValidator'
roleassign.services.yml in ./roleassign.services.yml
roleassign.services.yml
1 service uses RoleAssignUninstallValidator
roleassign.uninstall_validator in ./roleassign.services.yml
Drupal\roleassign\RoleAssignUninstallValidator

File

src/RoleAssignUninstallValidator.php, line 12

Namespace

Drupal\roleassign
View source
class RoleAssignUninstallValidator implements ModuleUninstallValidatorInterface {
  use StringTranslationTrait;

  /**
   * Constructs a new RoleAssignUninstallValidator.
   *
   * @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 = [];
    if ($this
      ->isCli()) {
      return $reasons;
    }
    if ($module == "roleassign") {
      if (!\Drupal::currentUser()
        ->hasPermission('administer roles')) {
        $reasons[] = $this
          ->t('You are not allowed to disable this module.');
      }
    }
    return $reasons;
  }

  /**
   * Indicates whether this is a CLI request.
   *
   * @return bool
   *   TRUE for a cli request, or FALSE.
   */
  public function isCli() {
    return PHP_SAPI === 'cli';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RoleAssignUninstallValidator::isCli public function Indicates whether this is a CLI request.
RoleAssignUninstallValidator::validate public function Determines the reasons a module can not be uninstalled. Overrides ModuleUninstallValidatorInterface::validate
RoleAssignUninstallValidator::__construct public function Constructs a new RoleAssignUninstallValidator.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
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.