Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / node / src / NodeViewBuilder.php
index f0971fb3bb8f81c254d25f1d1fdc52ca89bd7544..2fc67283f083719a987f228e75cf4a1e64dc5308 100644 (file)
@@ -2,10 +2,8 @@
 
 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.
@@ -35,6 +33,7 @@ class NodeViewBuilder extends EntityViewBuilder {
               $view_mode,
               $entity->language()->getId(),
               !empty($entity->in_preview),
+              $entity->isDefaultRevision() ? NULL : $entity->getLoadedRevisionId(),
             ],
           ],
         ];
@@ -78,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'],
@@ -90,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.
@@ -141,29 +146,4 @@ class NodeViewBuilder extends EntityViewBuilder {
     ];
   }
 
-  /**
-   * {@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()],
-        ];
-      }
-    }
-  }
-
 }