public function FieldModuleUninstallValidator::validate in Zircon Profile 8
Same name in this branch
- 8 core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php \Drupal\Core\Field\FieldModuleUninstallValidator::validate()
- 8 core/lib/Drupal/Core/ProxyClass/Field/FieldModuleUninstallValidator.php \Drupal\Core\ProxyClass\Field\FieldModuleUninstallValidator::validate()
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php \Drupal\Core\Field\FieldModuleUninstallValidator::validate()
Determines the reasons a module can not be uninstalled.
Example implementation:
public function validate($module) {
$entity_types = $this->entityManager->getDefinitions();
$reasons = array();
foreach ($entity_types as $entity_type) {
if ($module == $entity_type->getProvider() && $entity_type instanceof ContentEntityTypeInterface && $this->entityManager->getStorage($entity_type->id())->hasData()) {
$reasons[] = $this->t('There is content for the entity type: @entity_type', array('@entity_type' => $entity_type->getLabel()));
}
}
return $reasons;
}
Parameters
string $module: A module name.
Return value
string[] An array of reasons the module can not be uninstalled, empty if it can. Each reason should not end with any punctuation since multiple reasons can be displayed together.
Overrides ModuleUninstallValidatorInterface::validate
See also
template_preprocess_system_modules_uninstall()
File
- core/
lib/ Drupal/ Core/ Field/ FieldModuleUninstallValidator.php, line 41 - Contains \Drupal\Core\Field\FieldModuleUninstallValidator.
Class
- FieldModuleUninstallValidator
- Validates module uninstall readiness based on defined storage definitions.
Namespace
Drupal\Core\FieldCode
public function validate($module_name) {
$reasons = array();
// We skip fields provided by the Field module as it implements field
// purging.
if ($module_name != 'field') {
foreach ($this->entityManager
->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
->isSubclassOf('\\Drupal\\Core\\Entity\\FieldableEntityInterface')) {
foreach ($this->entityManager
->getFieldStorageDefinitions($entity_type_id) as $storage_definition) {
if ($storage_definition
->getProvider() == $module_name) {
$storage = $this->entityManager
->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', array(
'@field-name' => $storage_definition
->getName(),
'@entity_type' => $entity_type
->getLabel(),
));
}
}
}
}
}
}
return $reasons;
}