Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. EntityViewBuilder.php

function 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\Entity

Code

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(),
            ];
        }
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal