You are here

public static function MaestroEngine::removeTemplateTask in Maestro 8.2

Same name and namespace in other branches
  1. 3.x src/Engine/MaestroEngine.php \Drupal\maestro\Engine\MaestroEngine::removeTemplateTask()

Removes a template task.

Parameters

string $templateMachineName: Machine name of the Maestro Template.

string $taskToRemove: The machine name of the task to remove.

1 call to MaestroEngine::removeTemplateTask()
MaestroTemplateBuilderForm::removeTaskComplete in modules/maestro_template_builder/src/Form/MaestroTemplateBuilderForm.php
Ajax callback to remove a task from the template.

File

src/Engine/MaestroEngine.php, line 231

Class

MaestroEngine
Class MaestroEngine.

Namespace

Drupal\maestro\Engine

Code

public static function removeTemplateTask($templateMachineName, $taskToRemove) {
  $returnValue = FALSE;
  $template = MaestroEngine::getTemplate($templateMachineName);
  $templateTask = MaestroEngine::getTemplateTaskByID($templateMachineName, $taskToRemove);
  $pointers = MaestroEngine::getTaskPointersFromTemplate($templateMachineName, $taskToRemove);
  $tasks = $template->tasks;
  unset($tasks[$taskToRemove]);

  // We also have to remove all of the pointers that point to this task.
  foreach ($pointers as $pointer) {
    $nextsteps = explode(',', $tasks[$pointer]['nextstep']);
    $key = array_search($taskToRemove, $nextsteps);
    unset($nextsteps[$key]);
    $tasks[$pointer]['nextstep'] = implode(',', $nextsteps);
  }
  $template->tasks = $tasks;
  try {
    $returnValue = $template
      ->save();
  } catch (EntityStorageException $e) {

    // Something went wrong.  Catching it.  We will return FALSE to signify that it hasn't saved.
    $returnValue = FALSE;
  }
  return $returnValue;
}