You are here

public static function TaskHandler::getHandlerURL in Maestro 3.x

Same name and namespace in other branches
  1. 8.2 src/Utility/TaskHandler.php \Drupal\maestro\Utility\TaskHandler::getHandlerURL()

Get the handler's URL.

2 calls to TaskHandler::getHandlerURL()
MaestroEngineActiveHandler::render in src/Plugin/views/field/MaestroEngineActiveHandler.php
Renders the field.
maestro_tokens in ./maestro.module
Implements hook_tokens().

File

src/Utility/TaskHandler.php, line 53

Class

TaskHandler
Internal function that helps determine the handler type that is used for interactive tasks.

Namespace

Drupal\maestro\Utility

Code

public static function getHandlerURL($queueID) {
  global $base_url;
  $url = FALSE;
  $queueRecord = \Drupal::entityTypeManager()
    ->getStorage('maestro_queue')
    ->load($queueID);
  $templateMachineName = MaestroEngine::getTemplateIdFromProcessId($queueRecord->process_id
    ->getString());
  $query_options = [
    'queueid' => $queueID,
  ];
  $handler = $queueRecord->handler
    ->getString();
  if ($handler && !empty($handler) && $queueRecord->is_interactive
    ->getString() == '1') {
    $handler = str_replace($base_url, '', $handler);
    $handler_type = TaskHandler::getType($handler);
    $handler_url_parts = UrlHelper::parse($handler);
    $query_options += $handler_url_parts['query'];
  }
  elseif ($queueRecord->is_interactive
    ->getString() == '1' && empty($handler)) {

    // Handler is empty.  If this is an interactive task and has no handler, we're still OK.  This is an interactive function that uses a default handler then.
    $handler_type = 'function';
  }
  else {

    // This doesn't match, so return nothing.
    return FALSE;
  }
  $query_options += [
    'modal' => 'notmodal',
  ];
  switch ($handler_type) {
    case 'external':
      $url = Url::fromUri($handler, [
        'query' => $query_options,
      ])
        ->toString();
      break;
    case 'internal':
      $url = Url::fromUserInput($handler, [
        'query' => $query_options,
      ])
        ->toString();
      break;
    case 'function':
      $url = Url::fromRoute('maestro.execute', $query_options, [
        'absolute' => TRUE,
      ])
        ->toString();
      break;
    default:
      $url = FALSE;
      break;
  }
  return $url;
}