protected function EntityViewBuilder::addContextualLinks in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Entity/EntityViewBuilder.php \Drupal\Core\Entity\EntityViewBuilder::addContextualLinks()
- 10 core/lib/Drupal/Core/Entity/EntityViewBuilder.php \Drupal\Core\Entity\EntityViewBuilder::addContextualLinks()
Add contextual links.
Parameters
array $build: The render array that is being created.
\Drupal\Core\Entity\EntityInterface $entity: The entity to be prepared.
1 call to EntityViewBuilder::addContextualLinks()
- EntityViewBuilder::buildMultiple in core/lib/ Drupal/ Core/ Entity/ EntityViewBuilder.php 
- Builds multiple entities' views; augments entity defaults.
File
- core/lib/ Drupal/ Core/ Entity/ EntityViewBuilder.php, line 355 
Class
- EntityViewBuilder
- Base class for entity view builders.
Namespace
Drupal\Core\EntityCode
protected function addContextualLinks(array &$build, EntityInterface $entity) {
  if ($entity
    ->isNew()) {
    return;
  }
  $key = $entity
    ->getEntityTypeId();
  $rel = 'canonical';
  if ($entity instanceof ContentEntityInterface && !$entity
    ->isDefaultRevision()) {
    $rel = 'revision';
    $key .= '_revision';
  }
  if ($entity
    ->hasLinkTemplate($rel) && $entity
    ->toUrl($rel)
    ->isRouted()) {
    $build['#contextual_links'][$key] = [
      'route_parameters' => $entity
        ->toUrl($rel)
        ->getRouteParameters(),
    ];
    if ($entity instanceof EntityChangedInterface) {
      $build['#contextual_links'][$key]['metadata'] = [
        'changed' => $entity
          ->getChangedTime(),
      ];
    }
  }
}