class DepthUninstallValidator in Taxonomy Term Depth 8.2
Same name in this branch
- 8.2 src/DepthUninstallValidator.php \Drupal\taxonomy_term_depth\DepthUninstallValidator
- 8.2 src/ProxyClass/DepthUninstallValidator.php \Drupal\taxonomy_term_depth\ProxyClass\DepthUninstallValidator
Prevents uninstallation of modules providing active field storage.
Hierarchy
- class \Drupal\taxonomy_term_depth\DepthUninstallValidator implements ModuleUninstallValidatorInterface uses StringTranslationTrait
Expanded class hierarchy of DepthUninstallValidator
1 string reference to 'DepthUninstallValidator'
1 service uses DepthUninstallValidator
File
- src/
DepthUninstallValidator.php, line 16
Namespace
Drupal\taxonomy_term_depthView source
class DepthUninstallValidator implements ModuleUninstallValidatorInterface {
use StringTranslationTrait;
/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* DepthUninstallValidator constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
*/
public function __construct(EntityTypeManagerInterface $entity_manager, EntityFieldManagerInterface $entity_field_manager, TranslationInterface $string_translation) {
$this->entityTypeManager = $entity_manager;
$this->entityFieldManager = $entity_field_manager;
$this->stringTranslation = $string_translation;
}
/**
* {@inheritdoc}
*/
public function validate($module_name) {
$reasons = [];
// We skip fields provided by the Field module as it implements field
// purging.
if ($module_name != 'field') {
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
// We skip entity types defined by the module as there must be no
// content to be able to uninstall them anyway.
// See \Drupal\Core\Entity\ContentUninstallValidator.
if ($entity_type
->getProvider() != $module_name && $entity_type
->entityClassImplements('\\Drupal\\Core\\Entity\\FieldableEntityInterface')) {
foreach ($this->entityFieldManager
->getFieldStorageDefinitions($entity_type_id) as $storage_definition) {
if ($storage_definition
->getProvider() == $module_name) {
$storage = $this->entityTypeManager
->getStorage($entity_type_id);
if ($storage instanceof FieldableEntityStorageInterface && $storage
->countFieldData($storage_definition, TRUE)) {
$reasons[] = $this
->t('There is data for the field @field-name on entity type @entity_type. <a href=":url">Delete depth fields data.</a>.', [
'@field-name' => $storage_definition
->getName(),
'@entity_type' => $entity_type
->getLabel(),
':url' => Url::fromRoute('taxonomy_term_depth.prepare_modules_uninstall')
->toString(),
]);
}
}
}
}
}
}
return $reasons;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DepthUninstallValidator:: |
protected | property | ||
DepthUninstallValidator:: |
protected | property | ||
DepthUninstallValidator:: |
public | function |
Determines the reasons a module can not be uninstalled. Overrides ModuleUninstallValidatorInterface:: |
|
DepthUninstallValidator:: |
public | function | DepthUninstallValidator constructor. | |
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. |