namespace Drupal\node;
-use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityViewBuilder;
-use Drupal\node\Entity\Node;
/**
* View builder handler for nodes.
$view_mode,
$entity->language()->getId(),
!empty($entity->in_preview),
+ $entity->isDefaultRevision() ? NULL : $entity->getLoadedRevisionId(),
],
],
];
* The language in which the node entity is being viewed.
* @param bool $is_in_preview
* Whether the node is currently being previewed.
+ * @param $revision_id
+ * (optional) The identifier of the node revision to be loaded. If none
+ * is provided, the default revision will be loaded.
*
* @return array
* A renderable array representing the node links.
*/
- public static function renderLinks($node_entity_id, $view_mode, $langcode, $is_in_preview) {
+ public static function renderLinks($node_entity_id, $view_mode, $langcode, $is_in_preview, $revision_id = NULL) {
$links = [
'#theme' => 'links__node',
'#pre_render' => ['drupal_pre_render_links'],
];
if (!$is_in_preview) {
- $entity = Node::load($node_entity_id)->getTranslation($langcode);
+ $storage = \Drupal::entityTypeManager()->getStorage('node');
+ /** @var \Drupal\node\NodeInterface $revision */
+ $revision = !isset($revision_id) ? $storage->load($node_entity_id) : $storage->loadRevision($revision_id);
+ $entity = $revision->getTranslation($langcode);
$links['node'] = static::buildLinks($entity, $view_mode);
// Allow other modules to alter the node links.
];
}
- /**
- * {@inheritdoc}
- */
- 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()],
- ];
- }
- }
- }
-
}