You are here

public function MaestroEngineUserWhoCompleted::render in Maestro 3.x

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

Class

MaestroEngineUserWhoCompleted
Field handler to create a linkage to the user who completed a task.

Namespace

Drupal\maestro\Plugin\views\field

Code

public function render(ResultRow $values) {
  $result = '';
  $item = $values->_entity;

  // This will ONLY work for maestro queues.
  if ($item
    ->getEntityTypeId() == 'maestro_queue') {
    $usr = \Drupal::entityTypeManager()
      ->getStorage('user')
      ->load($item->uid
      ->getString());
    if ($usr) {
      $link_to_user = $usr
        ->toUrl('canonical')
        ->toString();
      switch ($this->options['user_display_style']) {
        case 'name':
          $result = $usr->name
            ->getString();
          break;
        case 'uid':
          $result = $item->uid
            ->getString();
          break;
        case 'email':
          $result = $usr->email
            ->getString();
          break;
      }
    }
  }
  else {
    return '';
  }
  if ($this->options['link_to_user'] && $result) {
    return [
      '#markup' => '<a href="' . $link_to_user . '" class="maestro_who_completed_field">' . $result . '</a>',
    ];
  }
  else {
    return $result;
  }
}