public function MaestroFormApprovalExampleUninstallValidator::validate in Maestro 3.x
Same name in this branch
- 3.x modules/examples/maestro_form_approval_example/src/MaestroFormApprovalExampleUninstallValidator.php \Drupal\maestro_form_approval_example\MaestroFormApprovalExampleUninstallValidator::validate()
- 3.x modules/examples/maestro_form_approval_example/src/ProxyClass/MaestroFormApprovalExampleUninstallValidator.php \Drupal\maestro_form_approval_example\ProxyClass\MaestroFormApprovalExampleUninstallValidator::validate()
Same name and namespace in other branches
- 8.2 modules/examples/maestro_form_approval_example/src/MaestroFormApprovalExampleUninstallValidator.php \Drupal\maestro_form_approval_example\MaestroFormApprovalExampleUninstallValidator::validate()
Determines the reasons a module can not be uninstalled.
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
- modules/
examples/ maestro_form_approval_example/ src/ MaestroFormApprovalExampleUninstallValidator.php, line 31
Class
- MaestroFormApprovalExampleUninstallValidator
- Prevents example task module from being uninstalled when the task is bound in a template.
Namespace
Drupal\maestro_form_approval_exampleCode
public function validate($module) {
$reasons = [];
if ($module == 'maestro_form_approval_example') {
// Search for any node content of type "approval_form".
$query = \Drupal::entityQuery('node')
->condition('type', 'approval_form');
$nids = $query
->execute();
if ($nids) {
$reasons[] = $this
->t('Uninstalling the module will orphan the Approval Form content.');
$url = Url::fromRoute('system.admin_content', [
'status' => 'All',
'type' => 'approval_form',
]);
$link = Link::fromTextAndUrl($this
->t('Click here to remove Approval Form content.'), $url);
$reasons[] = $link;
}
// Now detect if this task still has open tasks...
$query = \Drupal::entityQuery('maestro_process')
->condition('template_id', 'form_approval_flow')
->condition('complete', '0');
$pids = $query
->execute();
if ($pids) {
$reasons[] = $this
->t('There are active Form Approval Flow processes. Complete or delete the open processes before uninstalling.');
}
}
return $reasons;
}