NodeViewBuilder::alterBuild

protected NodeViewBuilder::alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)

Specific per-entity building.

Parameters

array $build: The render array that is being created.

\Drupal\Core\Entity\EntityInterface $entity: The entity to be prepared.

\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display: The entity view display holding the display options configured for the entity components.

string $view_mode: The view mode that should be used to prepare the entity.

Overrides EntityViewBuilder::alterBuild

File

core/modules/node/src/NodeViewBuilder.php, line 145

Class

NodeViewBuilder
View builder handler for nodes.

Namespace

Drupal\node

Code

protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  /** @var \Drupal\node\NodeInterface $entity */
  parent::alterBuild($build, $entity, $display, $view_mode);
  if ($entity->id()) {
    if ($entity->isDefaultRevision()) {
      $build['#contextual_links']['node'] = [
        'route_parameters' => ['node' => $entity->id()],
        'metadata' => ['changed' => $entity->getChangedTime()],
      ];
    }
    else {
      $build['#contextual_links']['node_revision'] = [
        'route_parameters' => [
          'node' => $entity->id(),
          'node_revision' => $entity->getRevisionId(),
        ],
        'metadata' => ['changed' => $entity->getChangedTime()],
      ];
    }
  }
}
doc_Drupal
2016-10-29 09:31:48
Comments
Leave a Comment

Please login to continue.