You are here

class FilebrowserUninstallValidator in Filebrowser 3.x

Same name and namespace in other branches
  1. 8.2 src/FilebrowserUninstallValidator.php \Drupal\filebrowser\FilebrowserUninstallValidator

Hierarchy

Expanded class hierarchy of FilebrowserUninstallValidator

1 string reference to 'FilebrowserUninstallValidator'
filebrowser.services.yml in ./filebrowser.services.yml
filebrowser.services.yml
1 service uses FilebrowserUninstallValidator
filebrowser.uninstall.validator in ./filebrowser.services.yml
Drupal\filebrowser\FilebrowserUninstallValidator

File

src/FilebrowserUninstallValidator.php, line 14

Namespace

Drupal\filebrowser
View source
class FilebrowserUninstallValidator implements ModuleUninstallValidatorInterface {
  use StringTranslationTrait;

  /**
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a new FilebrowserUninstallValidator.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface EntityTypeManager
   *   The entity query factory.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The string translation service.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
    $this->entityQuery = $entity_type_manager
      ->getStorage('node')
      ->getQuery();
    $this->stringTranslation = $string_translation;
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function validate($module) {
    $reasons = [];
    if ($module == 'filebrowser') {

      // The Filebrowser node type is provided by the Filebrowser module. Prevent uninstall
      // if there are any nodes of that type.
      if ($this
        ->hasNodes()) {
        $reasons[] = $this
          ->t('To uninstall Filebrowser, delete all nodes of type %type', [
          '%type' => 'dir_listing',
        ]);
      }
    }
    return $reasons;
  }

  /**
   * Determines if there is any filebrowser nodes or not.
   *
   * @return bool
   *   TRUE if there are filebrowser nodes, FALSE otherwise.
   */
  protected function hasNodes() {
    $nodes = $this->entityQuery
      ->condition('type', 'dir_listing')
      ->accessCheck(FALSE)
      ->range(0, 1)
      ->execute();
    return !empty($nodes);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FilebrowserUninstallValidator::$entityTypeManager protected property
FilebrowserUninstallValidator::hasNodes protected function Determines if there is any filebrowser nodes or not.
FilebrowserUninstallValidator::validate public function Determines the reasons a module can not be uninstalled. Overrides ModuleUninstallValidatorInterface::validate
FilebrowserUninstallValidator::__construct public function Constructs a new FilebrowserUninstallValidator.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
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.