You are here

class MaestroInteractiveExampleTaskUninstallValidator in Maestro 8.2

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

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

Hierarchy

Expanded class hierarchy of MaestroInteractiveExampleTaskUninstallValidator

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

File

modules/examples/maestro_interactive_task_plugin_example/src/MaestroInteractiveExampleTaskUninstallValidator.php, line 13

Namespace

Drupal\maestro_interactive_task_plugin_example
View source
class MaestroInteractiveExampleTaskUninstallValidator implements ModuleUninstallValidatorInterface {
  use StringTranslationTrait;

  /**
   * Constructs a new MaestroInteractiveExampleTaskUninstallValidator.
   *
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The string translation service.
   */
  public function __construct(TranslationInterface $string_translation) {

    // We only use string translation in this validator, the rest is up to the Maestro Engine.
    $this->stringTranslation = $string_translation;
  }

  /**
   * {@inheritdoc}
   */
  public function validate($module) {
    $reasons = [];
    if ($module == 'maestro_interactive_task_plugin_example') {

      // Cycle through all of the Maestro templates and determine if any of the tasks are of type MaestroIntExample.
      $templates = MaestroEngine::getTemplates();
      foreach ($templates as $template) {
        foreach ($template->tasks as $task) {
          if ($task['tasktype'] == 'MaestroIntExample') {
            $reasons[] = $this
              ->t('To uninstall the Interactive Plugin Task Example module, remove the Interactive Example task from the <em>:template</em> template.', [
              ':template' => $template->label,
            ]);
          }
        }
      }
    }
    return $reasons;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MaestroInteractiveExampleTaskUninstallValidator::validate public function Determines the reasons a module can not be uninstalled. Overrides ModuleUninstallValidatorInterface::validate
MaestroInteractiveExampleTaskUninstallValidator::__construct public function Constructs a new MaestroInteractiveExampleTaskUninstallValidator.
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.