summaryrefslogtreecommitdiffstats
path: root/core/modules/node/src
diff options
context:
space:
mode:
authoreffulgentsia2018-01-27 06:14:06 (GMT)
committereffulgentsia2018-01-27 06:14:06 (GMT)
commitf9365a0acc795b8f80743a99530672a21d421b0a (patch)
tree303e385bd380ef74a955cc6df321f64a8bdadc37 /core/modules/node/src
parent27700fa12901df10ce5b6563d9d22a7091529b08 (diff)
Issue #2939742 by plach, Wim Leers: Node links always load the default revision during rendering
Diffstat (limited to 'core/modules/node/src')
-rw-r--r--core/modules/node/src/NodeViewBuilder.php12
1 files changed, 9 insertions, 3 deletions
diff --git a/core/modules/node/src/NodeViewBuilder.php b/core/modules/node/src/NodeViewBuilder.php
index 2bb7f4a..2fc6728 100644
--- a/core/modules/node/src/NodeViewBuilder.php
+++ b/core/modules/node/src/NodeViewBuilder.php
@@ -4,7 +4,6 @@ namespace Drupal\node;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityViewBuilder;
-use Drupal\node\Entity\Node;
/**
* View builder handler for nodes.
@@ -34,6 +33,7 @@ class NodeViewBuilder extends EntityViewBuilder {
$view_mode,
$entity->language()->getId(),
!empty($entity->in_preview),
+ $entity->isDefaultRevision() ? NULL : $entity->getLoadedRevisionId(),
],
],
];
@@ -77,11 +77,14 @@ class NodeViewBuilder extends EntityViewBuilder {
* 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'],
@@ -89,7 +92,10 @@ class NodeViewBuilder extends EntityViewBuilder {
];
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.