You are here

public function MaestroEngineActiveHandler::render in Maestro 3.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/views/field/MaestroEngineActiveHandler.php \Drupal\maestro\Plugin\views\field\MaestroEngineActiveHandler::render()

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides FieldPluginBase::render

File

src/Plugin/views/field/MaestroEngineActiveHandler.php, line 70

Class

MaestroEngineActiveHandler
Field handler to create a usable link to the task via the handler field.

Namespace

Drupal\maestro\Plugin\views\field

Code

public function render(ResultRow $values) {
  global $base_url;
  $item = $values->_entity;

  // This will ONLY work for production assignments and/or maestro queues.
  if ($item
    ->getEntityTypeId() == 'maestro_production_assignments' || $item
    ->getEntityTypeId() == 'maestro_queue') {

    // We are of the right types.  So let's get the right queue ID.
    if ($item
      ->getEntityTypeId() == 'maestro_production_assignments') {
      $queueID = $item->queue_id
        ->getString();
    }
    else {
      $queueID = $item->id
        ->getString();
    }
    $taskhandler = TaskHandler::getHandlerURL($queueID);
    if (isset($this->options['show_as_link']) && $this->options['show_as_link'] == 1) {
      $build['handler'][$queueID]['execute'] = [
        '#type' => 'link',
        '#title' => isset($this->options['link_text']) ? $this->options['link_text'] : $this
          ->t('Link'),
        '#url' => Url::fromUri($taskhandler),
      ];
    }
    else {
      $build['handler'][$queueID]['execute'] = [
        '#plain_text' => $taskhandler,
      ];
    }
    return $build;
  }
  else {
    return '';
  }
}