You are here

public function MaestroEngineAdminOperations::render in Maestro 8.2

Same name and namespace in other branches
  1. 3.x src/Plugin/views/field/MaestroEngineAdminOperations.php \Drupal\maestro\Plugin\views\field\MaestroEngineAdminOperations::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/MaestroEngineAdminOperations.php, line 50

Class

MaestroEngineAdminOperations
Field handler to create Administrative Operations for a queue entry in views.

Namespace

Drupal\maestro\Plugin\views\field

Code

public function render(ResultRow $values) {
  $item = $values->_entity;
  $rows = [];
  $links = [];

  /*
   * Tracing mechanism needs the process ID
   */
  $processID = 0;
  if ($item
    ->getEntityTypeId() == 'maestro_production_assignments') {
    $queueRecord = MaestroEngine::getQueueEntryById($item->queue_id
      ->getString());
    $processID = $queueRecord->process_id
      ->getString();
  }
  elseif ($item
    ->getEntityTypeId() == 'maestro_queue') {
    $processID = $item->process_id
      ->getString();
  }
  elseif ($item
    ->getEntityTypeId() == 'maestro_process') {
    $processID = $item->process_id
      ->getString();
  }
  $links['trace'] = [
    'title' => t('Trace'),
    'url' => Url::fromRoute('maestro.trace', [
      'processID' => $processID,
    ]),
  ];

  /*
   * Reassignment mechanism: only works for queue and production assignment types
   */
  $assignees = [];
  if ($item
    ->getEntityTypeId() == 'maestro_production_assignments') {
    $assignees = MaestroEngine::getAssignedNamesOfQueueItem($item->queue_id
      ->getString(), TRUE);
  }
  elseif ($item
    ->getEntityTypeId() == 'maestro_queue') {
    $assignees = MaestroEngine::getAssignedNamesOfQueueItem($item->id
      ->getString(), TRUE);
  }

  /*
   * The assignees holds a keyed array telling us who is assigned and how.
   * We use this information to determine what to pass to the handlers for the operations
   * First, the reassign. for each of the assignees, provide a link to reassign
   */
  foreach ($assignees as $name => $assignment) {
    $links[$name] = [
      'title' => t('Reassign') . ' ' . $name,
      'url' => Url::fromRoute('maestro.reassign_task', [
        'assignmentID' => $assignment['id'],
      ]),
    ];
  }
  $rows[] = [
    'data' => [
      '#type' => 'operations',
      '#links' => $links,
    ],
  ];
  return $rows;
}