Unverified Commit c23c05c9 authored by alexpott's avatar alexpott
Browse files

Issue #2691675 by Berdir, Mile23, alexpott: Replace deprecated entityManager()...

Issue #2691675 by Berdir, Mile23, alexpott: Replace deprecated entityManager() in ControllerBase descendents
parent 2a8e1e0a
......@@ -129,6 +129,7 @@ public static function create(ContainerInterface $container) {
* instead.
*/
protected function entityManager() {
@trigger_error('ControllerBase::getEntityManager() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use ::getEntityTypeManager() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
if (!$this->entityManager) {
$this->entityManager = $this->container()->get('entity.manager');
}
......
......@@ -20,7 +20,7 @@ class EntityListController extends ControllerBase {
* \Drupal\Core\Render\RendererInterface::render().
*/
public function listing($entity_type) {
return $this->entityManager()->getListBuilder($entity_type)->render();
return $this->entityTypeManager()->getListBuilder($entity_type)->render();
}
}
......@@ -3,9 +3,10 @@
namespace Drupal\Core\Entity\Controller;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Render\RendererInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -13,13 +14,19 @@
* Defines a generic controller to render a single entity.
*/
class EntityViewController implements ContainerInjectionInterface {
use DeprecatedServicePropertyTrait;
/**
* The entity manager
* {@inheritdoc}
*/
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
protected $entityTypeManager;
/**
* The renderer service.
......@@ -31,13 +38,13 @@ class EntityViewController implements ContainerInjectionInterface {
/**
* Creates an EntityViewController object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
*/
public function __construct(EntityManagerInterface $entity_manager, RendererInterface $renderer) {
$this->entityManager = $entity_manager;
public function __construct(EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer) {
$this->entityTypeManager = $entity_type_manager;
$this->renderer = $renderer;
}
......@@ -46,7 +53,7 @@ public function __construct(EntityManagerInterface $entity_manager, RendererInte
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('entity_type.manager'),
$container->get('renderer')
);
}
......@@ -92,7 +99,7 @@ public function buildTitle(array $page) {
* \Drupal\Core\Render\RendererInterface::render().
*/
public function view(EntityInterface $_entity, $view_mode = 'full') {
$page = $this->entityManager
$page = $this->entityTypeManager
->getViewBuilder($_entity->getEntityTypeId())
->view($_entity, $view_mode);
......
......@@ -48,7 +48,7 @@ public static function create(ContainerInterface $container) {
* \Drupal\Core\Render\RendererInterface::render().
*/
public function feedAdd() {
$feed = $this->entityManager()->getStorage('aggregator_feed')->create();
$feed = $this->entityTypeManager()->getStorage('aggregator_feed')->create();
return $this->entityFormBuilder()->getForm($feed);
}
......@@ -71,7 +71,7 @@ protected function buildPageList(array $items, $feed_source = '') {
];
$build['feed_source'] = is_array($feed_source) ? $feed_source : ['#markup' => $feed_source];
if ($items) {
$build['items'] = $this->entityManager()->getViewBuilder('aggregator_item')
$build['items'] = $this->entityTypeManager()->getViewBuilder('aggregator_item')
->viewMultiple($items, 'default');
$build['pager'] = ['#type' => 'pager'];
}
......@@ -106,8 +106,8 @@ public function feedRefresh(FeedInterface $aggregator_feed) {
* \Drupal\Core\Render\RendererInterface::render().
*/
public function adminOverview() {
$entity_manager = $this->entityManager();
$feeds = $entity_manager->getStorage('aggregator_feed')
$entity_type_manager = $this->entityTypeManager();
$feeds = $entity_type_manager->getStorage('aggregator_feed')
->loadMultiple();
$header = [$this->t('Title'), $this->t('Items'), $this->t('Last update'), $this->t('Next update'), $this->t('Operations')];
......@@ -116,7 +116,7 @@ public function adminOverview() {
foreach ($feeds as $feed) {
$row = [];
$row[] = $feed->toLink()->toString();
$row[] = $this->formatPlural($entity_manager->getStorage('aggregator_item')->getItemCount($feed), '1 item', '@count items');
$row[] = $this->formatPlural($entity_type_manager->getStorage('aggregator_item')->getItemCount($feed), '1 item', '@count items');
$last_checked = $feed->getLastCheckedTime();
$refresh_rate = $feed->getRefreshRate();
......@@ -173,7 +173,7 @@ public function adminOverview() {
* The rendered list of items for the feed.
*/
public function pageLast() {
$items = $this->entityManager()->getStorage('aggregator_item')->loadAll(20);
$items = $this->entityTypeManager()->getStorage('aggregator_item')->loadAll(20);
$build = $this->buildPageList($items);
$build['#attached']['feed'][] = ['aggregator/rss', $this->config('system.site')->get('name') . ' ' . $this->t('aggregator')];
return $build;
......
......@@ -22,7 +22,7 @@ class BlockAddController extends ControllerBase {
*/
public function blockAddConfigureForm($plugin_id, $theme) {
// Create a block entity.
$entity = $this->entityManager()->getStorage('block')->create(['plugin' => $plugin_id, 'theme' => $theme]);
$entity = $this->entityTypeManager()->getStorage('block')->create(['plugin' => $plugin_id, 'theme' => $theme]);
return $this->entityFormBuilder()->getForm($entity);
}
......
......@@ -57,7 +57,7 @@ public function listing($theme = NULL, Request $request = NULL) {
throw new NotFoundHttpException();
}
return $this->entityManager()->getListBuilder('block')->render($theme, $request);
return $this->entityTypeManager()->getListBuilder('block')->render($theme, $request);
}
}
......@@ -122,7 +122,7 @@ public function bookRender() {
'#theme' => 'item_list',
'#items' => $book_list,
'#cache' => [
'tags' => \Drupal::entityManager()->getDefinition('node')->getListCacheTags(),
'tags' => $this->entityTypeManager()->getDefinition('node')->getListCacheTags(),
],
];
}
......
......@@ -8,8 +8,10 @@
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Cache\CacheableResponseInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
......@@ -40,11 +42,18 @@ class CommentController extends ControllerBase {
protected $commentManager;
/**
* The entity manager.
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityManager;
protected $entityFieldManager;
/**
* The entity repository.
*
* @var Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityRepository;
/**
* Constructs a CommentController object.
......@@ -53,13 +62,27 @@ class CommentController extends ControllerBase {
* HTTP kernel to handle requests.
* @param \Drupal\comment\CommentManagerInterface $comment_manager
* The comment manager service.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager service.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository service.
*/
public function __construct(HttpKernelInterface $http_kernel, CommentManagerInterface $comment_manager, EntityManagerInterface $entity_manager) {
public function __construct(HttpKernelInterface $http_kernel, CommentManagerInterface $comment_manager, EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager = NULL, EntityRepositoryInterface $entity_repository = NULL) {
$this->httpKernel = $http_kernel;
$this->commentManager = $comment_manager;
$this->entityManager = $entity_manager;
$this->entityTypeManager = $entity_type_manager;
if (!$entity_field_manager) {
@trigger_error('The entity_field.manager service must be passed to CommentController::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$entity_field_manager = \Drupal::service('entity_field.manager');
}
$this->entityFieldManager = $entity_field_manager;
if (!$entity_repository) {
@trigger_error('The entity.repository service must be passed to CommentController::__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;
}
/**
......@@ -69,7 +92,9 @@ public static function create(ContainerInterface $container) {
return new static(
$container->get('http_kernel'),
$container->get('comment.manager'),
$container->get('entity.manager')
$container->get('entity_type.manager'),
$container->get('entity_field.manager'),
$container->get('entity.repository')
);
}
......@@ -119,10 +144,10 @@ public function commentPermalink(Request $request, CommentInterface $comment) {
if (!$entity->access('view')) {
throw new AccessDeniedHttpException();
}
$field_definition = $this->entityManager()->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$comment->getFieldName()];
$field_definition = $this->entityFieldManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$comment->getFieldName()];
// Find the current display page for this comment.
$page = $this->entityManager()->getStorage('comment')->getDisplayOrdinal($comment, $field_definition->getSetting('default_mode'), $field_definition->getSetting('per_page'));
$page = $this->entityTypeManager()->getStorage('comment')->getDisplayOrdinal($comment, $field_definition->getSetting('default_mode'), $field_definition->getSetting('per_page'));
// @todo: Cleaner sub request handling.
$subrequest_url = $entity->toUrl()->setOption('query', ['page' => $page])->toString(TRUE);
$redirect_request = Request::create($subrequest_url->getGeneratedUrl(), 'GET', $request->query->all(), $request->cookies->all(), [], $request->server->all());
......@@ -155,7 +180,7 @@ public function commentPermalink(Request $request, CommentInterface $comment) {
* The translated comment subject.
*/
public function commentPermalinkTitle(CommentInterface $comment) {
return $this->entityManager()->getTranslationFromContext($comment)->label();
return $this->entityRepository->getTranslationFromContext($comment)->label();
}
/**
......@@ -219,9 +244,9 @@ public function getReplyForm(Request $request, EntityInterface $entity, $field_n
// $pid indicates that this is a reply to a comment.
if ($pid) {
// Load the parent comment.
$comment = $this->entityManager()->getStorage('comment')->load($pid);
$comment = $this->entityTypeManager()->getStorage('comment')->load($pid);
// Display the parent comment.
$build['comment_parent'] = $this->entityManager()->getViewBuilder('comment')->view($comment);
$build['comment_parent'] = $this->entityTypeManager()->getViewBuilder('comment')->view($comment);
}
// The comment is in response to a entity.
......@@ -231,7 +256,7 @@ public function getReplyForm(Request $request, EntityInterface $entity, $field_n
$entity = clone $entity;
$entity->{$field_name}->status = CommentItemInterface::HIDDEN;
// Render array of the entity full view mode.
$build['commented_entity'] = $this->entityManager()->getViewBuilder($entity->getEntityTypeId())->view($entity, 'full');
$build['commented_entity'] = $this->entityTypeManager()->getViewBuilder($entity->getEntityTypeId())->view($entity, 'full');
unset($build['commented_entity']['#cache']);
}
}
......@@ -240,7 +265,7 @@ public function getReplyForm(Request $request, EntityInterface $entity, $field_n
}
// Show the actual reply box.
$comment = $this->entityManager()->getStorage('comment')->create([
$comment = $this->entityTypeManager()->getStorage('comment')->create([
'entity_id' => $entity->id(),
'pid' => $pid,
'entity_type' => $entity->getEntityTypeId(),
......@@ -292,7 +317,7 @@ public function replyFormAccess(EntityInterface $entity, $field_name, $pid = NUL
$access = $access->andIf(AccessResult::allowedIfHasPermission($account, 'access comments'));
// Load the parent comment.
$comment = $this->entityManager()->getStorage('comment')->load($pid);
$comment = $this->entityTypeManager()->getStorage('comment')->load($pid);
// Check if the parent comment is published and belongs to the entity.
$access = $access->andIf(AccessResult::allowedIf($comment && $comment->isPublished() && $comment->getCommentedEntityId() == $entity->id()));
if ($comment) {
......@@ -329,9 +354,9 @@ public function renderNewCommentsNodeLinks(Request $request) {
$links = [];
foreach ($nids as $nid) {
$node = $this->entityManager->getStorage('node')->load($nid);
$node = $this->entityTypeManager()->getStorage('node')->load($nid);
$new = $this->commentManager->getCountNewComments($node);
$page_number = $this->entityManager()->getStorage('comment')
$page_number = $this->entityTypeManager()->getStorage('comment')
->getNewCommentPageNumber($node->{$field_name}->comment_count, $new, $node, $field_name);
$query = $page_number ? ['page' => $page_number] : NULL;
$links[$nid] = [
......
......@@ -63,7 +63,7 @@ public function listing($mapper_id) {
// controller defined, use it. Other mappers, for examples the ones for
// node_type and block, fallback to the generic configuration translation
// list controller.
$build = $this->entityManager()
$build = $this->entityTypeManager()
->getHandler($entity_type, 'config_translation_list')
->setMapperDefinition($mapper_definition)
->render();
......
......@@ -59,7 +59,7 @@ public function contactSitePage(ContactFormInterface $contact_form = NULL) {
// Use the default form if no form has been passed.
if (empty($contact_form)) {
$contact_form = $this->entityManager()
$contact_form = $this->entityTypeManager()
->getStorage('contact_form')
->load($config->get('default_form'));
// If there are no forms, do not display the form.
......@@ -76,7 +76,7 @@ public function contactSitePage(ContactFormInterface $contact_form = NULL) {
}
}
$message = $this->entityManager()
$message = $this->entityTypeManager()
->getStorage('contact_message')
->create([
'contact_form' => $contact_form->id(),
......@@ -109,7 +109,7 @@ public function contactPersonalPage(UserInterface $user) {
throw new NotFoundHttpException();
}
$message = $this->entityManager()->getStorage('contact_message')->create([
$message = $this->entityTypeManager()->getStorage('contact_message')->create([
'contact_form' => 'personal',
'recipient' => $user->id(),
]);
......
......@@ -7,6 +7,7 @@
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
......@@ -24,21 +25,38 @@ class ContentTranslationController extends ControllerBase {
*/
protected $manager;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Initializes a content translation controller.
*
* @param \Drupal\content_translation\ContentTranslationManagerInterface $manager
* A content translation manager instance.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager service.
*/
public function __construct(ContentTranslationManagerInterface $manager) {
public function __construct(ContentTranslationManagerInterface $manager, EntityFieldManagerInterface $entity_field_manager = NULL) {
$this->manager = $manager;
if (!$entity_field_manager) {
@trigger_error('The entity_field.manager service must be passed to ContentTranslationController::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$entity_field_manager = \Drupal::service('entity_field.manager');
}
$this->entityFieldManager = $entity_field_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('content_translation.manager'));
return new static(
$container->get('content_translation.manager'),
$container->get('entity_field.manager')
);
}
/**
......@@ -62,7 +80,7 @@ public function prepareTranslation(ContentEntityInterface $entity, LanguageInter
}
/** @var \Drupal\user\UserInterface $user */
$user = $this->entityManager()->getStorage('user')->load($this->currentUser()->id());
$user = $this->entityTypeManager()->getStorage('user')->load($this->currentUser()->id());
$metadata = $this->manager->getTranslationMetadata($target_translation);
// Update the translation author to current user, as well the translation
......@@ -85,7 +103,7 @@ public function overview(RouteMatchInterface $route_match, $entity_type_id = NUL
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $route_match->getParameter($entity_type_id);
$account = $this->currentUser();
$handler = $this->entityManager()->getHandler($entity_type_id, 'translation');
$handler = $this->entityTypeManager()->getHandler($entity_type_id, 'translation');
$manager = $this->manager;
$entity_type = $entity->getEntityType();
$use_latest_revisions = $entity_type->isRevisionable() && ContentTranslationManager::isPendingRevisionSupportEnabled($entity_type_id, $entity->bundle());
......@@ -108,7 +126,7 @@ public function overview(RouteMatchInterface $route_match, $entity_type_id = NUL
if ($this->languageManager()->isMultilingual()) {
// Determine whether the current entity is translatable.
$translatable = FALSE;
foreach ($this->entityManager->getFieldDefinitions($entity_type_id, $entity->bundle()) as $instance) {
foreach ($this->entityFieldManager->getFieldDefinitions($entity_type_id, $entity->bundle()) as $instance) {
if ($instance->isTranslatable()) {
$translatable = TRUE;
break;
......
......@@ -84,7 +84,7 @@ public function __construct(Connection $database, ModuleHandlerInterface $module
$this->moduleHandler = $module_handler;
$this->dateFormatter = $date_formatter;
$this->formBuilder = $form_builder;
$this->userStorage = $this->entityManager()->getStorage('user');
$this->userStorage = $this->entityTypeManager()->getStorage('user');
}
/**
......
......@@ -70,7 +70,7 @@ public function filterXss(Request $request, FilterFormatInterface $filter_format
$original_format_id = $request->request->get('original_format_id');
$original_format = NULL;
if (isset($original_format_id)) {
$original_format = $this->entityManager()
$original_format = $this->entityTypeManager()
->getStorage('filter_format')
->load($original_format_id);
}
......
......@@ -18,7 +18,7 @@ class EntityDisplayModeController extends ControllerBase {
*/
public function viewModeTypeSelection() {
$entity_types = [];
foreach ($this->entityManager()->getDefinitions() as $entity_type_id => $entity_type) {
foreach ($this->entityTypeManager()->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->get('field_ui_base_route') && $entity_type->hasViewBuilderClass()) {
$entity_types[$entity_type_id] = [
'title' => $entity_type->getLabel(),
......@@ -41,7 +41,7 @@ public function viewModeTypeSelection() {
*/
public function formModeTypeSelection() {
$entity_types = [];
foreach ($this->entityManager()->getDefinitions() as $entity_type_id => $entity_type) {
foreach ($this->entityTypeManager()->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->get('field_ui_base_route') && $entity_type->hasFormClasses()) {
$entity_types[$entity_type_id] = [
'title' => $entity_type->getLabel(),
......
......@@ -25,7 +25,7 @@ class FieldConfigListController extends EntityListController {
* \Drupal\Core\Render\RendererInterface::render().
*/
public function listing($entity_type_id = NULL, $bundle = NULL, RouteMatchInterface $route_match = NULL) {
return $this->entityManager()->getListBuilder('field_config')->render($entity_type_id, $bundle);
return $this->entityTypeManager()->getListBuilder('field_config')->render($entity_type_id, $bundle);
}
}
......@@ -5,6 +5,7 @@
use Drupal\Core\Cache\CacheableJsonResponse;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Image\ImageFactory;
use Drupal\Core\Render\Element\StatusMessages;
......@@ -41,6 +42,13 @@ class QuickEditImageController extends ControllerBase {
*/
protected $imageFactory;
/**
* The entity display repository service.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
protected $entityDisplayRepository;
/**
* Constructs a new QuickEditImageController.
*
......@@ -50,11 +58,18 @@ class QuickEditImageController extends ControllerBase {
* The image factory.
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
* The tempstore factory.
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
* The entity display repository service.
*/
public function __construct(RendererInterface $renderer, ImageFactory $image_factory, PrivateTempStoreFactory $temp_store_factory) {
public function __construct(RendererInterface $renderer, ImageFactory $image_factory, PrivateTempStoreFactory $temp_store_factory, EntityDisplayRepositoryInterface $entity_display_repository = NULL) {
$this->renderer = $renderer;
$this->imageFactory = $image_factory;
$this->tempStore = $temp_store_factory->get('quickedit');
if (!$entity_display_repository) {
@trigger_error('The entity_display.repository service must be passed to QuickEditImageController::__construct(), it is required before Drupal 9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$entity_display_repository = \Drupal::service('entity_display.repository');
}
$this->entityDisplayRepository = $entity_display_repository;
}
/**
......@@ -64,7 +79,8 @@ public static function create(ContainerInterface $container) {
return new static(
$container->get('renderer'),
$container->get('image.factory'),
$container->get('tempstore.private')
$container->get('tempstore.private'),
$container->get('entity_display.repository')
);
}
......@@ -115,7 +131,7 @@ public function upload(EntityInterface $entity, $field_name, $langcode, $view_mo
$entity->$field_name->setValue($value);
// Render the new image using the correct formatter settings.
$entity_view_mode_ids = array_keys($this->entityManager()->getViewModes($entity->getEntityTypeId()));
$entity_view_mode_ids = array_keys($this->entityDisplayRepository->getViewModes($entity->getEntityTypeId()));
if (in_array($view_mode_id, $entity_view_mode_ids, TRUE)) {
$output = $entity->$field_name->view($view_mode_id);
}
......
......@@ -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;
......@@ -32,6 +33,13 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa
*/
protected $renderer;
/**
* The entity repository service.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityRepository;
/**
* Constructs a NodeController object.
*
......@@ -39,10 +47,17 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa
* 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 function __construct(DateFormatterInterface $date_formatter, RendererInte
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 @@ public function addPage() {
$build = [
'#theme' => 'node_add_list',
'#cache' => [
'tags' => $this->entityManager()->getDefinition('node_type')->getListCacheTags(),
'tags' => $this->entityTypeManager()->getDefinition('node_type')->getListCacheTags(),
],
];
$content = [];