class FilebrowserUninstallValidator in Filebrowser 8.2
Same name and namespace in other branches
- 3.x src/FilebrowserUninstallValidator.php \Drupal\filebrowser\FilebrowserUninstallValidator
Hierarchy
- class \Drupal\filebrowser\FilebrowserUninstallValidator implements ModuleUninstallValidatorInterface uses StringTranslationTrait
Expanded class hierarchy of FilebrowserUninstallValidator
1 string reference to 'FilebrowserUninstallValidator'
1 service uses FilebrowserUninstallValidator
File
- src/
FilebrowserUninstallValidator.php, line 14
Namespace
Drupal\filebrowserView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FilebrowserUninstallValidator:: |
protected | property | ||
FilebrowserUninstallValidator:: |
protected | function | Determines if there is any filebrowser nodes or not. | |
FilebrowserUninstallValidator:: |
public | function |
Determines the reasons a module can not be uninstalled. Overrides ModuleUninstallValidatorInterface:: |
|
FilebrowserUninstallValidator:: |
public | function | Constructs a new FilebrowserUninstallValidator. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |