Mercurial > hg > isophonics-drupal-site
diff core/modules/node/src/Controller/NodeController.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | c2387f117808 |
children |
line wrap: on
line diff
--- a/core/modules/node/src/Controller/NodeController.php Thu Feb 28 13:21:36 2019 +0000 +++ b/core/modules/node/src/Controller/NodeController.php Thu May 09 15:33:08 2019 +0100 @@ -6,6 +6,7 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Url; use Drupal\node\NodeStorageInterface; @@ -33,16 +34,30 @@ protected $renderer; /** + * The entity repository service. + * + * @var \Drupal\Core\Entity\EntityRepositoryInterface + */ + protected $entityRepository; + + /** * Constructs a NodeController object. * * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter * The date formatter service. * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer service. + * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository + * The entity repository. */ - public function __construct(DateFormatterInterface $date_formatter, RendererInterface $renderer) { + public function __construct(DateFormatterInterface $date_formatter, RendererInterface $renderer, EntityRepositoryInterface $entity_repository = NULL) { $this->dateFormatter = $date_formatter; $this->renderer = $renderer; + if (!$entity_repository) { + @trigger_error('The entity.repository service must be passed to NodeController::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED); + $entity_repository = \Drupal::service('entity.repository'); + } + $this->entityRepository = $entity_repository; } /** @@ -51,7 +66,8 @@ public static function create(ContainerInterface $container) { return new static( $container->get('date.formatter'), - $container->get('renderer') + $container->get('renderer'), + $container->get('entity.repository') ); } @@ -70,15 +86,15 @@ $build = [ '#theme' => 'node_add_list', '#cache' => [ - 'tags' => $this->entityManager()->getDefinition('node_type')->getListCacheTags(), + 'tags' => $this->entityTypeManager()->getDefinition('node_type')->getListCacheTags(), ], ]; $content = []; // Only use node types the user has access to. - foreach ($this->entityManager()->getStorage('node_type')->loadMultiple() as $type) { - $access = $this->entityManager()->getAccessControlHandler('node')->createAccess($type->id(), NULL, [], TRUE); + foreach ($this->entityTypeManager()->getStorage('node_type')->loadMultiple() as $type) { + $access = $this->entityTypeManager()->getAccessControlHandler('node')->createAccess($type->id(), NULL, [], TRUE); if ($access->isAllowed()) { $content[$type->id()] = $type; } @@ -106,7 +122,7 @@ * A node submission form. */ public function add(NodeTypeInterface $node_type) { - $node = $this->entityManager()->getStorage('node')->create([ + $node = $this->entityTypeManager()->getStorage('node')->create([ 'type' => $node_type->id(), ]); @@ -125,9 +141,9 @@ * An array suitable for \Drupal\Core\Render\RendererInterface::render(). */ public function revisionShow($node_revision) { - $node = $this->entityManager()->getStorage('node')->loadRevision($node_revision); - $node = $this->entityManager()->getTranslationFromContext($node); - $node_view_controller = new NodeViewController($this->entityManager, $this->renderer, $this->currentUser()); + $node = $this->entityTypeManager()->getStorage('node')->loadRevision($node_revision); + $node = $this->entityRepository->getTranslationFromContext($node); + $node_view_controller = new NodeViewController($this->entityTypeManager(), $this->renderer, $this->currentUser(), $this->entityRepository); $page = $node_view_controller->view($node); unset($page['nodes'][$node->id()]['#cache']); return $page; @@ -143,8 +159,8 @@ * The page title. */ public function revisionPageTitle($node_revision) { - $node = $this->entityManager()->getStorage('node')->loadRevision($node_revision); - return $this->t('Revision of %title from %date', ['%title' => $node->label(), '%date' => format_date($node->getRevisionCreationTime())]); + $node = $this->entityTypeManager()->getStorage('node')->loadRevision($node_revision); + return $this->t('Revision of %title from %date', ['%title' => $node->label(), '%date' => $this->dateFormatter->format($node->getRevisionCreationTime())]); } /** @@ -162,7 +178,7 @@ $langname = $node->language()->getName(); $languages = $node->getTranslationLanguages(); $has_translations = (count($languages) > 1); - $node_storage = $this->entityManager()->getStorage('node'); + $node_storage = $this->entityTypeManager()->getStorage('node'); $type = $node->getType(); $build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => $node->label()]) : $this->t('Revisions for %title', ['%title' => $node->label()]); @@ -198,7 +214,7 @@ $link = $this->l($date, new Url('entity.node.revision', ['node' => $node->id(), 'node_revision' => $vid])); } else { - $link = $node->link($date); + $link = $node->toLink($date)->toString(); $current_revision_displayed = TRUE; }