You are here

public function MaestroInteractiveExampleTask::performValidityCheck in Maestro 3.x

Same name and namespace in other branches
  1. 8.2 modules/examples/maestro_interactive_task_plugin_example/src/Plugin/EngineTasks/MaestroInteractiveExampleTask.php \Drupal\maestro_interactive_task_plugin_example\Plugin\EngineTasks\MaestroInteractiveExampleTask::performValidityCheck()

Lets the task perform validation on itself. If the task is missing any internal requirements, it can flag itself as having an issue. Return array MUST be in the format of array( 'taskID' => the task machine name, 'taskLabel' => the human readable label for the task, 'reason' => the reason for the failure )

Parameters

array $validation_failure_tasks: The array of other validation failures.

array $validation_information_tasks: The array of informational messages.

array $task: The passed-in fully-loaded task from the template (array)

Overrides MaestroEngineTaskInterface::performValidityCheck

File

modules/examples/maestro_interactive_task_plugin_example/src/Plugin/EngineTasks/MaestroInteractiveExampleTask.php, line 234

Class

MaestroInteractiveExampleTask
Maestro Interactive Example Task Plugin.

Namespace

Drupal\maestro_interactive_task_plugin_example\Plugin\EngineTasks

Code

public function performValidityCheck(array &$validation_failure_tasks, array &$validation_information_tasks, array $task) {

  /*
   * When you use a task in the template builder, it will be up to the task to provide any sort of debugging and validation
   * information to the end user.  Do you have a field that MUST be set in order for the task to execute?
   * How about a field that doesn't have the right values?  This is where you would populate the
   * $validation_failure_tasks array with failure information and the
   * $validation_information_tasks with informational messages.
   *
   * See the MaestroEngineTaskInterface.php interface declaration of this method for details.
   */

  // We force-set the handler in our prepareTaskForSave method.
  // if for some reason this doesn't get set, we fail validation.
  if (array_key_exists('handler', $task) && $task['handler'] == '' || !array_key_exists('handler', $task)) {
    $validation_failure_tasks[] = [
      'taskID' => $task['id'],
      'taskLabel' => $task['label'],
      'reason' => t('The Example Interactive Task handler is missing and thus the engine will fail to show an execute link to the user. Try to edit and resave the task.'),
    ];
  }

  // Forcing the modal option to appear as well, so we check for it.
  if (array_key_exists('modal', $task['data']) && $task['data']['modal'] == '' || !array_key_exists('modal', $task['data'])) {
    $validation_failure_tasks[] = [
      'taskID' => $task['id'],
      'taskLabel' => $task['label'],
      'reason' => t('The Example Interactive Task modal option is missing. Try to edit and resave the task.'),
    ];
  }
}