You are here

class MaestroFormApprovalExampleUninstallValidator in Maestro 8.2

Same name in this branch
  1. 8.2 modules/examples/maestro_form_approval_example/src/MaestroFormApprovalExampleUninstallValidator.php \Drupal\maestro_form_approval_example\MaestroFormApprovalExampleUninstallValidator
  2. 8.2 modules/examples/maestro_form_approval_example/src/ProxyClass/MaestroFormApprovalExampleUninstallValidator.php \Drupal\maestro_form_approval_example\ProxyClass\MaestroFormApprovalExampleUninstallValidator
Same name and namespace in other branches
  1. 3.x modules/examples/maestro_form_approval_example/src/MaestroFormApprovalExampleUninstallValidator.php \Drupal\maestro_form_approval_example\MaestroFormApprovalExampleUninstallValidator

Prevents example task module from being uninstalled when the task is bound in a template.

Hierarchy

Expanded class hierarchy of MaestroFormApprovalExampleUninstallValidator

1 string reference to 'MaestroFormApprovalExampleUninstallValidator'
maestro_form_approval_example.services.yml in modules/examples/maestro_form_approval_example/maestro_form_approval_example.services.yml
modules/examples/maestro_form_approval_example/maestro_form_approval_example.services.yml
1 service uses MaestroFormApprovalExampleUninstallValidator
maestro_form_approval_example.uninstall_validator in modules/examples/maestro_form_approval_example/maestro_form_approval_example.services.yml
Drupal\maestro_form_approval_example\MaestroFormApprovalExampleUninstallValidator

File

modules/examples/maestro_form_approval_example/src/MaestroFormApprovalExampleUninstallValidator.php, line 14

Namespace

Drupal\maestro_form_approval_example
View source
class MaestroFormApprovalExampleUninstallValidator implements ModuleUninstallValidatorInterface {
  use StringTranslationTrait;

  /**
   * Constructs a new MaestroFormApprovalExampleUninstallValidator.
   *
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The string translation service.
   */
  public function __construct(TranslationInterface $string_translation) {
    $this->stringTranslation = $string_translation;
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MaestroFormApprovalExampleUninstallValidator::validate public function Determines the reasons a module can not be uninstalled. Overrides ModuleUninstallValidatorInterface::validate
MaestroFormApprovalExampleUninstallValidator::__construct public function Constructs a new MaestroFormApprovalExampleUninstallValidator.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.