class UninstallValidator in Lightning Media 8.4
Same name in this branch
- 8.4 modules/lightning_media_slideshow/src/UninstallValidator.php \Drupal\lightning_media_slideshow\UninstallValidator
- 8.4 modules/lightning_media_slideshow/src/ProxyClass/UninstallValidator.php \Drupal\lightning_media_slideshow\ProxyClass\UninstallValidator
Same name and namespace in other branches
- 8.3 modules/lightning_media_slideshow/src/UninstallValidator.php \Drupal\lightning_media_slideshow\UninstallValidator
Prevents this module from being uninstalled if any slideshow blocks exist.
Hierarchy
- class \Drupal\lightning_media_slideshow\UninstallValidator implements ModuleUninstallValidatorInterface uses StringTranslationTrait
Expanded class hierarchy of UninstallValidator
1 string reference to 'UninstallValidator'
- lightning_media_slideshow.services.yml in modules/
lightning_media_slideshow/ lightning_media_slideshow.services.yml - modules/lightning_media_slideshow/lightning_media_slideshow.services.yml
1 service uses UninstallValidator
- lightning_media_slideshow.uninstall_validator in modules/
lightning_media_slideshow/ lightning_media_slideshow.services.yml - \Drupal\lightning_media_slideshow\UninstallValidator
File
- modules/
lightning_media_slideshow/ src/ UninstallValidator.php, line 13
Namespace
Drupal\lightning_media_slideshowView source
class UninstallValidator implements ModuleUninstallValidatorInterface {
use StringTranslationTrait;
/**
* The block content entity storage handler.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $blockContentStorage;
/**
* Constructs a new validator.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
$this->blockContentStorage = $entity_type_manager
->getStorage('block_content');
$this
->setStringTranslation($string_translation);
}
/**
* {@inheritdoc}
*/
public function validate($module) {
$problems = [];
if ($module === 'lightning_media_slideshow' && $this
->hasSlideshowBlocks()) {
$problems[] = $this
->t('To uninstall Media Slideshow, you must delete all slideshow blocks first.');
}
return $problems;
}
/**
* Determines if any slideshow blocks exist.
*
* @return bool
* TRUE if there are slideshow blocks, FALSE otherwise.
*/
protected function hasSlideshowBlocks() {
$count = $this->blockContentStorage
->getQuery()
->condition('type', 'media_slideshow')
->accessCheck(FALSE)
->count()
->execute();
return !empty($count);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
UninstallValidator:: |
protected | property | The block content entity storage handler. | |
UninstallValidator:: |
protected | function | Determines if any slideshow blocks exist. | |
UninstallValidator:: |
public | function |
Determines the reasons a module can not be uninstalled. Overrides ModuleUninstallValidatorInterface:: |
|
UninstallValidator:: |
public | function | Constructs a new validator. |