Same name in this branch
- 10 core/modules/filter/src/FilterUninstallValidator.php \Drupal\filter\FilterUninstallValidator
- 10 core/modules/filter/src/ProxyClass/FilterUninstallValidator.php \Drupal\filter\ProxyClass\FilterUninstallValidator
Same name and namespace in other branches
- 8.9.x core/modules/filter/src/FilterUninstallValidator.php \Drupal\filter\FilterUninstallValidator
- 9 core/modules/filter/src/FilterUninstallValidator.php \Drupal\filter\FilterUninstallValidator
Prevents uninstallation of modules providing used filter plugins.
Hierarchy
- class \Drupal\filter\FilterUninstallValidator implements ModuleUninstallValidatorInterface uses StringTranslationTrait
Expanded class hierarchy of FilterUninstallValidator
1 string reference to 'FilterUninstallValidator'
- filter.services.yml in core/
modules/ filter/ filter.services.yml - core/modules/filter/filter.services.yml
1 service uses FilterUninstallValidator
- filter.uninstall_validator in core/
modules/ filter/ filter.services.yml - Drupal\filter\FilterUninstallValidator
File
- core/
modules/ filter/ src/ FilterUninstallValidator.php, line 14
Namespace
Drupal\filterView source
class FilterUninstallValidator implements ModuleUninstallValidatorInterface {
use StringTranslationTrait;
/**
* The filter plugin manager.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface
*/
protected $filterManager;
/**
* The filter entity storage.
*
* @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface
*/
protected $filterStorage;
/**
* Constructs a new FilterUninstallValidator.
*
* @param \Drupal\Component\Plugin\PluginManagerInterface $filter_manager
* The filter plugin manager.
* @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(PluginManagerInterface $filter_manager, EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
$this->filterManager = $filter_manager;
$this->filterStorage = $entity_type_manager
->getStorage('filter_format');
$this->stringTranslation = $string_translation;
}
/**
* {@inheritdoc}
*/
public function validate($module) {
$reasons = [];
// Get filter plugins supplied by this module.
if ($filter_plugins = $this
->getFilterDefinitionsByProvider($module)) {
$used_in = [];
// Find out if any filter formats have the plugin enabled.
foreach ($this
->getEnabledFilterFormats() as $filter_format) {
$filters = $filter_format
->filters();
foreach ($filter_plugins as $filter_plugin) {
if ($filters
->has($filter_plugin['id']) && $filters
->get($filter_plugin['id'])->status) {
$used_in[] = $filter_format
->label();
break;
}
}
}
if (!empty($used_in)) {
$reasons[] = $this
->t('Provides a filter plugin that is in use in the following filter formats: %formats', [
'%formats' => implode(', ', $used_in),
]);
}
}
return $reasons;
}
/**
* Returns all filter definitions that are provided by the specified provider.
*
* @param string $provider
* The provider of the filters.
*
* @return array
* The filter definitions for the specified provider.
*/
protected function getFilterDefinitionsByProvider($provider) {
return array_filter($this->filterManager
->getDefinitions(), function ($definition) use ($provider) {
return $definition['provider'] == $provider;
});
}
/**
* Returns all enabled filter formats.
*
* @return \Drupal\filter\FilterFormatInterface[]
*/
protected function getEnabledFilterFormats() {
return $this->filterStorage
->loadByProperties([
'status' => TRUE,
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FilterUninstallValidator:: |
protected | property | The filter plugin manager. | |
FilterUninstallValidator:: |
protected | property | The filter entity storage. | |
FilterUninstallValidator:: |
protected | function | Returns all enabled filter formats. | |
FilterUninstallValidator:: |
protected | function | Returns all filter definitions that are provided by the specified provider. | |
FilterUninstallValidator:: |
public | function |
Determines the reasons a module can not be uninstalled. Overrides ModuleUninstallValidatorInterface:: |
|
FilterUninstallValidator:: |
public | function | Constructs a new FilterUninstallValidator. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 3 |
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. | 1 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |