Mercurial > hg > isophonics-drupal-site
annotate core/modules/node/src/Controller/NodePreviewController.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children | af1871eacc83 |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\node\Controller; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\Core\Entity\EntityInterface; |
Chris@0 | 6 use Drupal\Core\Entity\Controller\EntityViewController; |
Chris@0 | 7 |
Chris@0 | 8 /** |
Chris@0 | 9 * Defines a controller to render a single node in preview. |
Chris@0 | 10 */ |
Chris@0 | 11 class NodePreviewController extends EntityViewController { |
Chris@0 | 12 |
Chris@0 | 13 /** |
Chris@0 | 14 * {@inheritdoc} |
Chris@0 | 15 */ |
Chris@0 | 16 public function view(EntityInterface $node_preview, $view_mode_id = 'full', $langcode = NULL) { |
Chris@0 | 17 $node_preview->preview_view_mode = $view_mode_id; |
Chris@0 | 18 $build = parent::view($node_preview, $view_mode_id); |
Chris@0 | 19 |
Chris@0 | 20 $build['#attached']['library'][] = 'node/drupal.node.preview'; |
Chris@0 | 21 |
Chris@0 | 22 // Don't render cache previews. |
Chris@0 | 23 unset($build['#cache']); |
Chris@0 | 24 |
Chris@0 | 25 return $build; |
Chris@0 | 26 } |
Chris@0 | 27 |
Chris@0 | 28 /** |
Chris@0 | 29 * The _title_callback for the page that renders a single node in preview. |
Chris@0 | 30 * |
Chris@0 | 31 * @param \Drupal\Core\Entity\EntityInterface $node_preview |
Chris@0 | 32 * The current node. |
Chris@0 | 33 * |
Chris@0 | 34 * @return string |
Chris@0 | 35 * The page title. |
Chris@0 | 36 */ |
Chris@0 | 37 public function title(EntityInterface $node_preview) { |
Chris@0 | 38 return $this->entityManager->getTranslationFromContext($node_preview)->label(); |
Chris@0 | 39 } |
Chris@0 | 40 |
Chris@0 | 41 } |