Chris@0: entityRepository = $entity_repository; Chris@18: } Chris@18: Chris@18: /** Chris@18: * {@inheritdoc} Chris@18: */ Chris@18: public static function create(ContainerInterface $container) { Chris@18: return new static( Chris@18: $container->get('entity_type.manager'), Chris@18: $container->get('renderer'), Chris@18: $container->get('entity.repository') Chris@18: ); Chris@18: } Chris@18: Chris@18: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function view(EntityInterface $node_preview, $view_mode_id = 'full', $langcode = NULL) { Chris@0: $node_preview->preview_view_mode = $view_mode_id; Chris@0: $build = parent::view($node_preview, $view_mode_id); Chris@0: Chris@0: $build['#attached']['library'][] = 'node/drupal.node.preview'; Chris@0: Chris@0: // Don't render cache previews. Chris@0: unset($build['#cache']); Chris@0: Chris@0: return $build; Chris@0: } Chris@0: Chris@0: /** Chris@0: * The _title_callback for the page that renders a single node in preview. Chris@0: * Chris@0: * @param \Drupal\Core\Entity\EntityInterface $node_preview Chris@0: * The current node. Chris@0: * Chris@0: * @return string Chris@0: * The page title. Chris@0: */ Chris@0: public function title(EntityInterface $node_preview) { Chris@18: return $this->entityRepository->getTranslationFromContext($node_preview)->label(); Chris@0: } Chris@0: Chris@0: }