comparison core/modules/node/src/Controller/NodePreviewController.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php 1 <?php
2 2
3 namespace Drupal\node\Controller; 3 namespace Drupal\node\Controller;
4 4
5 use Drupal\Core\Entity\Controller\EntityViewController;
5 use Drupal\Core\Entity\EntityInterface; 6 use Drupal\Core\Entity\EntityInterface;
6 use Drupal\Core\Entity\Controller\EntityViewController; 7 use Drupal\Core\Entity\EntityRepositoryInterface;
8 use Drupal\Core\Entity\EntityTypeManagerInterface;
9 use Drupal\Core\Render\RendererInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
7 11
8 /** 12 /**
9 * Defines a controller to render a single node in preview. 13 * Defines a controller to render a single node in preview.
10 */ 14 */
11 class NodePreviewController extends EntityViewController { 15 class NodePreviewController extends EntityViewController {
16
17 /**
18 * The entity repository service.
19 *
20 * @var \Drupal\Core\Entity\EntityRepositoryInterface
21 */
22 protected $entityRepository;
23
24 /**
25 * Creates an NodeViewController object.
26 *
27 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
28 * The entity type manager.
29 * @param \Drupal\Core\Render\RendererInterface $renderer
30 * The renderer service.
31 * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
32 * The entity repository.
33 */
34 public function __construct(EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer, EntityRepositoryInterface $entity_repository = NULL) {
35 parent::__construct($entity_type_manager, $renderer);
36 if (!$entity_repository) {
37 @trigger_error('The entity.repository service must be passed to NodePreviewController::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
38 $entity_repository = \Drupal::service('entity.repository');
39 }
40 $this->entityRepository = $entity_repository;
41 }
42
43 /**
44 * {@inheritdoc}
45 */
46 public static function create(ContainerInterface $container) {
47 return new static(
48 $container->get('entity_type.manager'),
49 $container->get('renderer'),
50 $container->get('entity.repository')
51 );
52 }
12 53
13 /** 54 /**
14 * {@inheritdoc} 55 * {@inheritdoc}
15 */ 56 */
16 public function view(EntityInterface $node_preview, $view_mode_id = 'full', $langcode = NULL) { 57 public function view(EntityInterface $node_preview, $view_mode_id = 'full', $langcode = NULL) {
33 * 74 *
34 * @return string 75 * @return string
35 * The page title. 76 * The page title.
36 */ 77 */
37 public function title(EntityInterface $node_preview) { 78 public function title(EntityInterface $node_preview) {
38 return $this->entityManager->getTranslationFromContext($node_preview)->label(); 79 return $this->entityRepository->getTranslationFromContext($node_preview)->label();
39 } 80 }
40 81
41 } 82 }