class LocalStockUninstallValidator in Commerce Stock 8
Provides link to delete commerce_stock_local field values.
Hierarchy
- class \Drupal\commerce_stock_local\LocalStockUninstallValidator implements ModuleUninstallValidatorInterface uses StringTranslationTrait
Expanded class hierarchy of LocalStockUninstallValidator
1 string reference to 'LocalStockUninstallValidator'
- commerce_stock_local.services.yml in modules/
local_storage/ commerce_stock_local.services.yml - modules/local_storage/commerce_stock_local.services.yml
1 service uses LocalStockUninstallValidator
File
- modules/
local_storage/ src/ LocalStockUninstallValidator.php, line 17
Namespace
Drupal\commerce_stock_localView source
class LocalStockUninstallValidator implements ModuleUninstallValidatorInterface {
use StringTranslationTrait;
/**
* The entity_type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity_field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Constructs a new LocalStockUninstallValidator.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity_field manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation, EntityFieldManagerInterface $entity_field_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->stringTranslation = $string_translation;
$this->entityFieldManager = $entity_field_manager;
}
/**
* {@inheritdoc}
*/
public function validate($module) {
if ($module !== 'commerce_stock_local') {
return [];
}
$entity_types = $this->entityTypeManager
->getDefinitions();
$reasons = [];
foreach ($entity_types as $entity_type_id => $entity_type) {
if ($entity_type
->entityClassImplements('\\Drupal\\commerce\\PurchasableEntityInterface')) {
$storage = $this->entityTypeManager
->getStorage($entity_type_id);
if ($storage instanceof SqlContentEntityStorage) {
foreach ($this->entityFieldManager
->getActiveFieldStorageDefinitions($entity_type_id) as $storage_definition) {
if ($storage_definition
->getProvider() == $module && $storage instanceof FieldableEntityStorageInterface && $storage
->countFieldData($storage_definition, TRUE)) {
$reasons[] = $this
->t('<a href=":url">Remove field values</a>: @field-name on entity type @entity_type.', [
'@field-name' => $storage_definition
->getName(),
'@entity_type' => $entity_type
->getLabel(),
':url' => Url::fromRoute('commerce_stock_local.prepare_module_uninstall')
->toString(),
]);
}
}
}
}
}
return $reasons;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LocalStockUninstallValidator:: |
protected | property | The entity_field manager. | |
LocalStockUninstallValidator:: |
protected | property | The entity_type manager. | |
LocalStockUninstallValidator:: |
public | function |
Determines the reasons a module can not be uninstalled. Overrides ModuleUninstallValidatorInterface:: |
|
LocalStockUninstallValidator:: |
public | function | Constructs a new LocalStockUninstallValidator. | |
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. |