You are here

public function EntityLink::preRender in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/comment/src/Plugin/views/field/EntityLink.php \Drupal\comment\Plugin\views\field\EntityLink::preRender()

Runs before any fields are rendered.

This gives the handlers some time to set up before any handler has been rendered.

Parameters

\Drupal\views\ResultRow[] $values: An array of all ResultRow objects returned from the query.

Overrides FieldPluginBase::preRender

File

core/modules/comment/src/Plugin/views/field/EntityLink.php, line 56

Class

EntityLink
Handler for showing comment module's entity links.

Namespace

Drupal\comment\Plugin\views\field

Code

public function preRender(&$values) {

  // Render all nodes, so you can grep the comment links.
  $entities = [];
  foreach ($values as $row) {
    $entity = $row->_entity;
    $entities[$entity
      ->id()] = $entity;
  }
  if ($entities) {
    $entityTypeId = reset($entities)
      ->getEntityTypeId();
    $viewMode = $this->options['teaser'] ? 'teaser' : 'full';
    $this->build = \Drupal::entityTypeManager()
      ->getViewBuilder($entityTypeId)
      ->viewMultiple($entities, $viewMode);
  }
}