class FieldUninstallValidator in Zircon Profile 8
Same name in this branch
- 8 core/modules/field/src/FieldUninstallValidator.php \Drupal\field\FieldUninstallValidator
- 8 core/modules/field/src/ProxyClass/FieldUninstallValidator.php \Drupal\field\ProxyClass\FieldUninstallValidator
Same name and namespace in other branches
- 8.0 core/modules/field/src/FieldUninstallValidator.php \Drupal\field\FieldUninstallValidator
Prevents uninstallation of modules providing active field storage.
Hierarchy
- class \Drupal\field\FieldUninstallValidator implements ModuleUninstallValidatorInterface uses StringTranslationTrait
Expanded class hierarchy of FieldUninstallValidator
1 string reference to 'FieldUninstallValidator'
- field.services.yml in core/
modules/ field/ field.services.yml - core/modules/field/field.services.yml
1 service uses FieldUninstallValidator
- field.uninstall_validator in core/
modules/ field/ field.services.yml - Drupal\field\FieldUninstallValidator
File
- core/
modules/ field/ src/ FieldUninstallValidator.php, line 18 - Contains \Drupal\field\FieldUninstallValidator.
Namespace
Drupal\fieldView source
class FieldUninstallValidator implements ModuleUninstallValidatorInterface {
use StringTranslationTrait;
/**
* The field storage config storage.
*
* @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface
*/
protected $fieldStorageConfigStorage;
/**
* Constructs a new FieldUninstallValidator.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
*/
public function __construct(EntityManagerInterface $entity_manager, TranslationInterface $string_translation) {
$this->fieldStorageConfigStorage = $entity_manager
->getStorage('field_storage_config');
$this->stringTranslation = $string_translation;
}
/**
* {@inheritdoc}
*/
public function validate($module) {
$reasons = [];
if ($field_storages = $this
->getFieldStoragesByModule($module)) {
// Provide an explanation message (only mention pending deletions if there
// remain no actual, non-deleted fields.)
$non_deleted = FALSE;
foreach ($field_storages as $field_storage) {
if (!$field_storage
->isDeleted()) {
$non_deleted = TRUE;
break;
}
}
if ($non_deleted) {
$reasons[] = $this
->t('Fields type(s) in use');
}
else {
$reasons[] = $this
->t('Fields pending deletion');
}
}
return $reasons;
}
/**
* Returns all field storages for a specified module.
*
* @param string $module
* The module to filter field storages by.
*
* @return \Drupal\field\FieldStorageConfigInterface[]
* An array of field storages for a specified module.
*/
protected function getFieldStoragesByModule($module) {
return $this->fieldStorageConfigStorage
->loadByProperties([
'module' => $module,
'include_deleted' => TRUE,
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FieldUninstallValidator:: |
protected | property | The field storage config storage. | |
FieldUninstallValidator:: |
protected | function | Returns all field storages for a specified module. | |
FieldUninstallValidator:: |
public | function |
Determines the reasons a module can not be uninstalled. Overrides ModuleUninstallValidatorInterface:: |
|
FieldUninstallValidator:: |
public | function | Constructs a new FieldUninstallValidator. | |
StringTranslationTrait:: |
protected | property | The string translation service. | |
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. |