Skip to content
Snippets Groups Projects
Commit 1ece3c65 authored by Bojan Zivanovic's avatar Bojan Zivanovic
Browse files

Merge pull request #23 from dawehner/contextual-links

Provide contextual links for all entity types
parents c1128e64 9b5da5c9
No related branches found
No related tags found
No related merge requests found
<?php
/**
* @file
* Contains \Drupal\entity\EntityViewBuilder.
*/
namespace Drupal\entity;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityViewBuilder as CoreEntityViewBuilder;
/**
* Provides a entity view builder with contextual links support
*/
class EntityViewBuilder extends CoreEntityViewBuilder {
/**
* {@inheritdoc}
*/
protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
$entity_type_id = $entity->getEntityTypeId();
if (($entity instanceof ContentEntityInterface && $entity->isDefaultRevision()) || !$entity->getEntityType()->isRevisionable()) {
$build['#contextual_links'][$entity_type_id] = [
'route_parameters' => [
$entity_type_id => $entity->id()
],
];
}
else {
$build['#contextual_links'][$entity_type_id . '_revision'] = [
'route_parameters' => [
$entity_type_id => $entity->id(),
$entity_type_id . '_revision' => $entity->getRevisionId(),
],
];
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment