You are here

public function MaestroEngineProcessInitiator::render in Maestro 3.x

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

Class

MaestroEngineProcessInitiator
Field handler to translate the UID field into a username.

Namespace

Drupal\maestro\Plugin\views\field

Code

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

  // This will ONLY work for processes.
  if ($item
    ->getEntityTypeId() == 'maestro_process') {
    $usr = User::load(intval($item->initiator_uid
      ->getString()));
    if ($usr) {
      if (isset($this->options['show_as_link']) && $this->options['show_as_link'] == 1) {
        $build['initiator_username'] = [
          '#type' => 'link',
          '#title' => $usr
            ->getAccountName(),
          '#url' => Url::fromRoute('entity.user.canonical', [
            'user' => $usr
              ->id(),
          ]),
        ];
      }
      else {
        $build['initiator_username'] = [
          '#plain_text' => $usr
            ->getAccountName(),
        ];
      }
    }
    return $build;
  }
  else {
    return '';
  }
}