3 namespace Drupal\entity;
5 use Drupal\Core\Entity\ContentEntityInterface;
6 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
7 use Drupal\Core\Entity\EntityInterface;
8 use Drupal\Core\Entity\EntityViewBuilder as CoreEntityViewBuilder;
11 * Provides a entity view builder with contextual links support
13 class EntityViewBuilder extends CoreEntityViewBuilder {
18 protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
19 $entity_type_id = $entity->getEntityTypeId();
20 if (($entity instanceof ContentEntityInterface && $entity->isDefaultRevision()) || !$entity->getEntityType()->isRevisionable()) {
21 $build['#contextual_links'][$entity_type_id] = [
22 'route_parameters' => [
23 $entity_type_id => $entity->id()
28 $build['#contextual_links'][$entity_type_id . '_revision'] = [
29 'route_parameters' => [
30 $entity_type_id => $entity->id(),
31 $entity_type_id . '_revision' => $entity->getRevisionId(),