Mercurial > hg > isophonics-drupal-site
comparison core/modules/node/src/NodeViewBuilder.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\node; | 3 namespace Drupal\node; |
4 | 4 |
5 use Drupal\Core\Entity\Display\EntityViewDisplayInterface; | |
6 use Drupal\Core\Entity\EntityInterface; | 5 use Drupal\Core\Entity\EntityInterface; |
7 use Drupal\Core\Entity\EntityViewBuilder; | 6 use Drupal\Core\Entity\EntityViewBuilder; |
8 use Drupal\node\Entity\Node; | |
9 | 7 |
10 /** | 8 /** |
11 * View builder handler for nodes. | 9 * View builder handler for nodes. |
12 */ | 10 */ |
13 class NodeViewBuilder extends EntityViewBuilder { | 11 class NodeViewBuilder extends EntityViewBuilder { |
33 get_called_class() . '::renderLinks', [ | 31 get_called_class() . '::renderLinks', [ |
34 $entity->id(), | 32 $entity->id(), |
35 $view_mode, | 33 $view_mode, |
36 $entity->language()->getId(), | 34 $entity->language()->getId(), |
37 !empty($entity->in_preview), | 35 !empty($entity->in_preview), |
36 $entity->isDefaultRevision() ? NULL : $entity->getLoadedRevisionId(), | |
38 ], | 37 ], |
39 ], | 38 ], |
40 ]; | 39 ]; |
41 } | 40 } |
42 | 41 |
76 * The view mode in which the node entity is being viewed. | 75 * The view mode in which the node entity is being viewed. |
77 * @param string $langcode | 76 * @param string $langcode |
78 * The language in which the node entity is being viewed. | 77 * The language in which the node entity is being viewed. |
79 * @param bool $is_in_preview | 78 * @param bool $is_in_preview |
80 * Whether the node is currently being previewed. | 79 * Whether the node is currently being previewed. |
80 * @param $revision_id | |
81 * (optional) The identifier of the node revision to be loaded. If none | |
82 * is provided, the default revision will be loaded. | |
81 * | 83 * |
82 * @return array | 84 * @return array |
83 * A renderable array representing the node links. | 85 * A renderable array representing the node links. |
84 */ | 86 */ |
85 public static function renderLinks($node_entity_id, $view_mode, $langcode, $is_in_preview) { | 87 public static function renderLinks($node_entity_id, $view_mode, $langcode, $is_in_preview, $revision_id = NULL) { |
86 $links = [ | 88 $links = [ |
87 '#theme' => 'links__node', | 89 '#theme' => 'links__node', |
88 '#pre_render' => ['drupal_pre_render_links'], | 90 '#pre_render' => ['drupal_pre_render_links'], |
89 '#attributes' => ['class' => ['links', 'inline']], | 91 '#attributes' => ['class' => ['links', 'inline']], |
90 ]; | 92 ]; |
91 | 93 |
92 if (!$is_in_preview) { | 94 if (!$is_in_preview) { |
93 $entity = Node::load($node_entity_id)->getTranslation($langcode); | 95 $storage = \Drupal::entityTypeManager()->getStorage('node'); |
96 /** @var \Drupal\node\NodeInterface $revision */ | |
97 $revision = !isset($revision_id) ? $storage->load($node_entity_id) : $storage->loadRevision($revision_id); | |
98 $entity = $revision->getTranslation($langcode); | |
94 $links['node'] = static::buildLinks($entity, $view_mode); | 99 $links['node'] = static::buildLinks($entity, $view_mode); |
95 | 100 |
96 // Allow other modules to alter the node links. | 101 // Allow other modules to alter the node links. |
97 $hook_context = [ | 102 $hook_context = [ |
98 'view_mode' => $view_mode, | 103 'view_mode' => $view_mode, |
139 '#links' => $links, | 144 '#links' => $links, |
140 '#attributes' => ['class' => ['links', 'inline']], | 145 '#attributes' => ['class' => ['links', 'inline']], |
141 ]; | 146 ]; |
142 } | 147 } |
143 | 148 |
144 /** | |
145 * {@inheritdoc} | |
146 */ | |
147 protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) { | |
148 /** @var \Drupal\node\NodeInterface $entity */ | |
149 parent::alterBuild($build, $entity, $display, $view_mode); | |
150 if ($entity->id()) { | |
151 if ($entity->isDefaultRevision()) { | |
152 $build['#contextual_links']['node'] = [ | |
153 'route_parameters' => ['node' => $entity->id()], | |
154 'metadata' => ['changed' => $entity->getChangedTime()], | |
155 ]; | |
156 } | |
157 else { | |
158 $build['#contextual_links']['node_revision'] = [ | |
159 'route_parameters' => [ | |
160 'node' => $entity->id(), | |
161 'node_revision' => $entity->getRevisionId(), | |
162 ], | |
163 'metadata' => ['changed' => $entity->getChangedTime()], | |
164 ]; | |
165 } | |
166 } | |
167 } | |
168 | |
169 } | 149 } |