You are here

public function MaestroTaskConsoleController::getStatus in Maestro 8.2

Same name and namespace in other branches
  1. 3.x modules/maestro_taskconsole/src/Controller/MaestroTaskConsoleController.php \Drupal\maestro_taskconsole\Controller\MaestroTaskConsoleController::getStatus()

Method to fetch the status of a process.

1 string reference to 'MaestroTaskConsoleController::getStatus'
maestro_taskconsole.routing.yml in modules/maestro_taskconsole/maestro_taskconsole.routing.yml
modules/maestro_taskconsole/maestro_taskconsole.routing.yml

File

modules/maestro_taskconsole/src/Controller/MaestroTaskConsoleController.php, line 272

Class

MaestroTaskConsoleController
Maestro Task Console Controller.

Namespace

Drupal\maestro_taskconsole\Controller

Code

public function getStatus($processID, $queueID) {
  $build = [];
  $replace = [];
  $status_bar = '';
  $canExecute = MaestroEngine::canUserExecuteTask($queueID, \Drupal::currentUser()
    ->id());
  if ($canExecute) {
    $queueRecord = \Drupal::entityTypeManager()
      ->getStorage('maestro_queue')
      ->load($queueID);
    $templateMachineName = MaestroEngine::getTemplateIdFromProcessId($processID);
    $taskTemplate = MaestroEngine::getTemplateTaskByID($templateMachineName, $queueRecord->task_id
      ->getString());
    $template = MaestroEngine::getTemplate($templateMachineName);
    $var_workflow_stage_count = intval(MaestroEngine::getProcessVariable('workflow_timeline_stage_count', $processID));
    $build = MaestroStatus::getMaestroStatusBar($processID, $queueID, FALSE);

    // Now determine if we should show the views attached.
    $taskDetails = '';
    $customInformation = '';
    if (isset($template->show_details) && $template->show_details) {

      // We provide an invokation here to allow other modules to inject their own
      // custom information into the task display.
      \Drupal::moduleHandler()
        ->invokeAll('maestro_task_console_custominformation_alter', [
        &$customInformation,
        $taskTemplate,
        $queueRecord,
        $templateMachineName,
      ]);

      // Lets see if there's any views attached that we should be showing.
      if (isset($template->views_attached)) {
        foreach ($template->views_attached as $machine_name => $arr) {
          $view = Views::getView($machine_name);
          if ($view) {
            $display = explode(';', $arr['view_display']);
            $display_to_use = isset($display[0]) ? $display[0] : 'default';
            $render_build = $view
              ->buildRenderable($display_to_use, [
              $processID,
              $queueID,
            ], FALSE);
            if ($render_build) {
              $thisViewOutput = \Drupal::service('renderer')
                ->render($render_build);
              if ($thisViewOutput) {
                $task_information_render_array = [
                  '#theme' => 'taskconsole_views',
                  '#task_information' => $thisViewOutput,
                  '#title' => $view->storage
                    ->label(),
                ];
                $taskDetails .= \Drupal::service('renderer')
                  ->render($task_information_render_array);
              }
            }
          }
        }
      }

      // Anyone want to override the task details display?
      \Drupal::moduleHandler()
        ->invokeAll('maestro_task_console_taskdetails_alter', [
        &$taskDetails,
        $taskTemplate,
        $queueRecord,
        $templateMachineName,
      ]);
      $build['custom_information_bar'] = [
        '#children' => '<div class="custom-information">' . $customInformation . '</div>',
      ];
      $build['views_bar'] = [
        '#children' => '<div class="maestro-task-details">' . $taskDetails . '</div>',
      ];
      $replace['expand'] = [
        '#attributes' => [
          'class' => [
            'maestro-timeline-status',
            'maestro-status-toggle-up',
          ],
          'title' => $this
            ->t('Close Details'),
        ],
        '#type' => 'link',
        '#id' => 'maestro-id-ajax-' . $queueID,
        '#url' => Url::fromRoute('maestro_taskconsole.status_ajax_close', [
          'processID' => $processID,
          'queueID' => $queueID,
        ]),
        '#title' => $this
          ->t('Close Details'),
        '#ajax' => [
          'progress' => [
            'type' => 'throbber',
            'message' => NULL,
          ],
        ],
      ];
    }
  }

  // We can target the ID of DIV within the table row associated to the expanded task's information as we're able to inject a DIV via the #prefix/#suffix
  // However, we can only inject CSS as a #wrapper_attribute for the "link" and as such, we target the unique class wrapper TD element for the link for replacement.
  $response = new AjaxResponse();

  // Row.
  $response
    ->addCommand(new HtmlCommand('#maestro-ajax-' . $queueID, $build));

  // Wrapper attribute TD tag.
  $response
    ->addCommand(new HtmlCommand('.maestro-status-toggle-' . $queueID . '', $replace['expand']));
  $response
    ->addCommand(new CssCommand('#' . $queueID . '_ajax', [
    'display' => 'table-row',
  ]));
  return $response;
}