Commit 7dcda1f6 authored by alexpott's avatar alexpott

Issue #2977107 by Berdir, alexpott, jibran, larowlan: Use more specific...

Issue #2977107 by Berdir, alexpott, jibran, larowlan: Use more specific entity.manager services in module .services.yml files
parent c00be4c4
services:
basic_auth.authentication.basic_auth:
class: Drupal\basic_auth\Authentication\Provider\BasicAuth
arguments: ['@config.factory', '@user.auth', '@flood', '@entity.manager']
arguments: ['@config.factory', '@user.auth', '@flood', '@entity_type.manager']
tags:
- { name: authentication_provider, provider_id: 'basic_auth', priority: 100 }
basic_auth.page_cache_request_policy.disallow_basic_auth_requests:
......
......@@ -7,7 +7,8 @@
use Drupal\Core\Authentication\AuthenticationProviderChallengeInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Flood\FloodInterface;
use Drupal\Core\Http\Exception\CacheableUnauthorizedHttpException;
use Drupal\user\UserAuthInterface;
......@@ -18,6 +19,12 @@
* HTTP Basic authentication provider.
*/
class BasicAuth implements AuthenticationProviderInterface, AuthenticationProviderChallengeInterface {
use DeprecatedServicePropertyTrait;
/**
* {@inheritdoc}
*/
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
/**
* The config factory.
......@@ -41,11 +48,11 @@ class BasicAuth implements AuthenticationProviderInterface, AuthenticationProvid
protected $flood;
/**
* The entity manager.
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityManager;
protected $entityTypeManager;
/**
* Constructs a HTTP basic authentication provider object.
......@@ -56,14 +63,14 @@ class BasicAuth implements AuthenticationProviderInterface, AuthenticationProvid
* The user authentication service.
* @param \Drupal\Core\Flood\FloodInterface $flood
* The flood 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.
*/
public function __construct(ConfigFactoryInterface $config_factory, UserAuthInterface $user_auth, FloodInterface $flood, EntityManagerInterface $entity_manager) {
public function __construct(ConfigFactoryInterface $config_factory, UserAuthInterface $user_auth, FloodInterface $flood, EntityTypeManagerInterface $entity_type_manager) {
$this->configFactory = $config_factory;
$this->userAuth = $user_auth;
$this->flood = $flood;
$this->entityManager = $entity_manager;
$this->entityTypeManager = $entity_type_manager;
}
/**
......@@ -90,7 +97,7 @@ public function authenticate(Request $request) {
// in to many different user accounts. We have a reasonably high limit
// since there may be only one apparent IP for all users at an institution.
if ($this->flood->isAllowed('basic_auth.failed_login_ip', $flood_config->get('ip_limit'), $flood_config->get('ip_window'))) {
$accounts = $this->entityManager->getStorage('user')->loadByProperties(['name' => $username, 'status' => 1]);
$accounts = $this->entityTypeManager->getStorage('user')->loadByProperties(['name' => $username, 'status' => 1]);
$account = reset($accounts);
if ($account) {
if ($flood_config->get('uid_only')) {
......@@ -110,7 +117,7 @@ public function authenticate(Request $request) {
$uid = $this->userAuth->authenticate($username, $password);
if ($uid) {
$this->flood->clear('basic_auth.failed_login_user', $identifier);
return $this->entityManager->getStorage('user')->load($uid);
return $this->entityTypeManager->getStorage('user')->load($uid);
}
else {
// Register a per-user failed login event.
......
......@@ -9,4 +9,4 @@ services:
- { name: event_subscriber }
block.repository:
class: Drupal\block\BlockRepository
arguments: ['@entity.manager', '@theme.manager', '@context.handler']
arguments: ['@entity_type.manager', '@theme.manager', '@context.handler']
......@@ -3,7 +3,7 @@
namespace Drupal\block;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Context\ContextHandlerInterface;
use Drupal\Core\Theme\ThemeManagerInterface;
......@@ -29,15 +29,15 @@ class BlockRepository implements BlockRepositoryInterface {
/**
* Constructs a new BlockRepository.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
* The theme manager.
* @param \Drupal\Core\Plugin\Context\ContextHandlerInterface $context_handler
* The plugin context handler.
*/
public function __construct(EntityManagerInterface $entity_manager, ThemeManagerInterface $theme_manager, ContextHandlerInterface $context_handler) {
$this->blockStorage = $entity_manager->getStorage('block');
public function __construct(EntityTypeManagerInterface $entity_type_manager, ThemeManagerInterface $theme_manager, ContextHandlerInterface $context_handler) {
$this->blockStorage = $entity_type_manager->getStorage('block');
$this->themeManager = $theme_manager;
$this->contextHandler = $context_handler;
}
......
services:
block_test.multiple_static_context:
class: Drupal\block_test\ContextProvider\MultipleStaticContext
arguments: ['@current_user', '@entity.manager']
arguments: ['@current_user', '@entity_type.manager']
tags:
- { name: 'context_provider' }
......@@ -3,7 +3,7 @@
namespace Drupal\block_test\ContextProvider;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Context\ContextProviderInterface;
use Drupal\Core\Plugin\Context\EntityContext;
use Drupal\Core\Session\AccountInterface;
......@@ -32,12 +32,12 @@ class MultipleStaticContext implements ContextProviderInterface {
*
* @param \Drupal\Core\Session\AccountInterface $account
* The current user.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(AccountInterface $account, EntityManagerInterface $entity_manager) {
public function __construct(AccountInterface $account, EntityTypeManagerInterface $entity_type_manager) {
$this->account = $account;
$this->userStorage = $entity_manager->getStorage('user');
$this->userStorage = $entity_type_manager->getStorage('user');
}
/**
......
......@@ -10,6 +10,7 @@
use Drupal\block\BlockRepository;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContextAwarePluginInterface;
use Drupal\Tests\UnitTestCase;
......@@ -66,12 +67,13 @@ protected function setUp() {
$this->contextHandler = $this->getMock('Drupal\Core\Plugin\Context\ContextHandlerInterface');
$this->blockStorage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$entity_manager->expects($this->any())
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject $entity_type_manager */
$entity_type_manager = $this->createMock(EntityTypeManagerInterface::class);
$entity_type_manager->expects($this->any())
->method('getStorage')
->willReturn($this->blockStorage);
$this->blockRepository = new BlockRepository($entity_manager, $theme_manager, $this->contextHandler);
$this->blockRepository = new BlockRepository($entity_type_manager, $theme_manager, $this->contextHandler);
}
/**
......
services:
book.breadcrumb:
class: Drupal\book\BookBreadcrumbBuilder
arguments: ['@entity.manager', '@current_user']
arguments: ['@entity_type.manager', '@current_user']
tags:
- { name: breadcrumb_builder, priority: 701 }
book.manager:
class: Drupal\book\BookManager
arguments: ['@entity.manager', '@string_translation', '@config.factory', '@book.outline_storage', '@renderer']
arguments: ['@entity_type.manager', '@string_translation', '@config.factory', '@book.outline_storage', '@renderer']
book.outline:
class: Drupal\book\BookOutline
arguments: ['@book.manager']
book.export:
class: Drupal\book\BookExport
arguments: ['@entity.manager', '@book.manager']
arguments: ['@entity_type.manager', '@book.manager']
book.outline_storage:
class: Drupal\book\BookOutlineStorage
arguments: ['@database']
......
......@@ -4,7 +4,7 @@
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
......@@ -34,13 +34,13 @@ class BookBreadcrumbBuilder implements BreadcrumbBuilderInterface {
/**
* Constructs the BookBreadcrumbBuilder.
*
* @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\Session\AccountInterface $account
* The current user account.
*/
public function __construct(EntityManagerInterface $entity_manager, AccountInterface $account) {
$this->nodeStorage = $entity_manager->getStorage('node');
public function __construct(EntityTypeManagerInterface $entity_type_manager, AccountInterface $account) {
$this->nodeStorage = $entity_type_manager->getStorage('node');
$this->account = $account;
}
......
......@@ -2,7 +2,7 @@
namespace Drupal\book;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\node\NodeInterface;
/**
......@@ -36,14 +36,14 @@ class BookExport {
/**
* Constructs a BookExport object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entityManager
* The entity manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\book\BookManagerInterface $book_manager
* The book manager.
*/
public function __construct(EntityManagerInterface $entityManager, BookManagerInterface $book_manager) {
$this->nodeStorage = $entityManager->getStorage('node');
$this->viewBuilder = $entityManager->getViewBuilder('node');
public function __construct(EntityTypeManagerInterface $entity_type_manager, BookManagerInterface $book_manager) {
$this->nodeStorage = $entity_type_manager->getStorage('node');
$this->viewBuilder = $entity_type_manager->getViewBuilder('node');
$this->bookManager = $book_manager;
}
......
......@@ -4,7 +4,8 @@
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Session\AccountInterface;
......@@ -19,6 +20,12 @@
*/
class BookManager implements BookManagerInterface {
use StringTranslationTrait;
use DeprecatedServicePropertyTrait;
/**
* {@inheritdoc}
*/
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
/**
* Defines the maximum supported depth of the book tree.
......@@ -26,11 +33,11 @@ class BookManager implements BookManagerInterface {
const BOOK_MAX_DEPTH = 9;
/**
* Entity manager Service Object.
* Entity type manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityManager;
protected $entityTypeManager;
/**
* Config Factory Service Object.
......@@ -69,9 +76,20 @@ class BookManager implements BookManagerInterface {
/**
* Constructs a BookManager object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation
* The string translation service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\book\BookOutlineStorageInterface $book_outline_storage
* The book outline storage.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
*/
public function __construct(EntityManagerInterface $entity_manager, TranslationInterface $translation, ConfigFactoryInterface $config_factory, BookOutlineStorageInterface $book_outline_storage, RendererInterface $renderer) {
$this->entityManager = $entity_manager;
public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $translation, ConfigFactoryInterface $config_factory, BookOutlineStorageInterface $book_outline_storage, RendererInterface $renderer) {
$this->entityTypeManager = $entity_type_manager;
$this->stringTranslation = $translation;
$this->configFactory = $config_factory;
$this->bookOutlineStorage = $book_outline_storage;
......@@ -97,7 +115,7 @@ protected function loadBooks() {
if ($nids) {
$book_links = $this->bookOutlineStorage->loadMultiple($nids);
$nodes = $this->entityManager->getStorage('node')->loadMultiple($nids);
$nodes = $this->entityTypeManager->getStorage('node')->loadMultiple($nids);
// @todo: Sort by weight and translated title.
// @todo: use route name for links, not system path.
......@@ -413,7 +431,7 @@ protected function recurseTableOfContents(array $tree, $indent, array &$toc, arr
}
}
$nodes = $this->entityManager->getStorage('node')->loadMultiple($nids);
$nodes = $this->entityTypeManager->getStorage('node')->loadMultiple($nids);
foreach ($tree as $data) {
$nid = $data['link']['nid'];
......@@ -449,7 +467,7 @@ public function deleteFromBook($nid) {
if ($nid == $original['bid']) {
// Handle deletion of a top-level post.
$result = $this->bookOutlineStorage->loadBookChildren($nid);
$children = $this->entityManager->getStorage('node')->loadMultiple(array_keys($result));
$children = $this->entityTypeManager->getStorage('node')->loadMultiple(array_keys($result));
foreach ($children as $child) {
$child->book['bid'] = $child->id();
$this->updateOutline($child);
......@@ -576,7 +594,7 @@ protected function buildItems(array $tree) {
// Allow book-specific theme overrides.
$element['attributes'] = new Attribute();
$element['title'] = $data['link']['title'];
$node = $this->entityManager->getStorage('node')->load($data['link']['nid']);
$node = $this->entityTypeManager->getStorage('node')->load($data['link']['nid']);
$element['url'] = $node->toUrl();
$element['localized_options'] = !empty($data['link']['localized_options']) ? $data['link']['localized_options'] : [];
$element['localized_options']['set_active_class'] = TRUE;
......@@ -995,14 +1013,14 @@ public function bookLinkTranslate(&$link) {
$node = NULL;
// Access will already be set in the tree functions.
if (!isset($link['access'])) {
$node = $this->entityManager->getStorage('node')->load($link['nid']);
$node = $this->entityTypeManager->getStorage('node')->load($link['nid']);
$link['access'] = $node && $node->access('view');
}
// For performance, don't localize a link the user can't access.
if ($link['access']) {
// @todo - load the nodes en-mass rather than individually.
if (!$node) {
$node = $this->entityManager->getStorage('node')
$node = $this->entityTypeManager->getStorage('node')
->load($link['nid']);
}
// The node label will be the value for the current user's language.
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\book\Unit;
use Drupal\book\BookManager;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Tests\UnitTestCase;
/**
......@@ -57,7 +58,7 @@ class BookManagerTest extends UnitTestCase {
* {@inheritdoc}
*/
protected function setUp() {
$this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$this->entityManager = $this->createMock(EntityTypeManagerInterface::class);
$this->translation = $this->getStringTranslationStub();
$this->configFactory = $this->getConfigFactoryStub([]);
$this->bookOutlineStorage = $this->getMock('Drupal\book\BookOutlineStorageInterface');
......
services:
comment.breadcrumb:
class: Drupal\comment\CommentBreadcrumbBuilder
arguments: ['@entity.manager']
arguments: ['@entity_type.manager']
tags:
- { name: breadcrumb_builder, priority: 100 }
comment.manager:
class: Drupal\comment\CommentManager
arguments: ['@entity.manager', '@config.factory', '@string_translation', '@module_handler', '@current_user']
arguments: ['@entity_type.manager', '@config.factory', '@string_translation', '@module_handler', '@current_user', '@entity_field.manager']
comment.statistics:
class: Drupal\comment\CommentStatistics
arguments: ['@database', '@current_user', '@entity.manager', '@state', '@database.replica']
arguments: ['@database', '@current_user', '@entity_type.manager', '@state', '@database.replica']
tags:
- { name: backend_overridable }
comment.lazy_builders:
class: Drupal\comment\CommentLazyBuilders
arguments: ['@entity.manager', '@entity.form_builder', '@current_user', '@comment.manager', '@module_handler', '@renderer']
arguments: ['@entity_type.manager', '@entity.form_builder', '@current_user', '@comment.manager', '@module_handler', '@renderer']
comment.link_builder:
class: Drupal\comment\CommentLinkBuilder
arguments: ['@current_user', '@comment.manager', '@module_handler', '@string_translation', '@entity.manager']
arguments: ['@current_user', '@comment.manager', '@module_handler', '@string_translation', '@entity_type.manager']
......@@ -4,7 +4,7 @@
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
......@@ -25,11 +25,11 @@ class CommentBreadcrumbBuilder implements BreadcrumbBuilderInterface {
/**
* Constructs the CommentBreadcrumbBuilder.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityManagerInterface $entity_manager) {
$this->storage = $entity_manager->getStorage('comment');
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->storage = $entity_type_manager->getStorage('comment');
}
/**
......
......@@ -3,9 +3,10 @@
namespace Drupal\comment;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityFormBuilderInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Session\AccountInterface;
......@@ -15,13 +16,19 @@
* Defines a service for comment #lazy_builder callbacks.
*/
class CommentLazyBuilders {
use DeprecatedServicePropertyTrait;
/**
* The entity manager service.
* {@inheritdoc}
*/
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityManager;
protected $entityTypeManager;
/**
* The entity form builder service.
......@@ -61,8 +68,8 @@ class CommentLazyBuilders {
/**
* Constructs a new CommentLazyBuilders object.
*
* @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\EntityFormBuilderInterface $entity_form_builder
* The entity form builder service.
* @param \Drupal\Core\Session\AccountInterface $current_user
......@@ -74,8 +81,8 @@ class CommentLazyBuilders {
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
*/
public function __construct(EntityManagerInterface $entity_manager, EntityFormBuilderInterface $entity_form_builder, AccountInterface $current_user, CommentManagerInterface $comment_manager, ModuleHandlerInterface $module_handler, RendererInterface $renderer) {
$this->entityManager = $entity_manager;
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityFormBuilderInterface $entity_form_builder, AccountInterface $current_user, CommentManagerInterface $comment_manager, ModuleHandlerInterface $module_handler, RendererInterface $renderer) {
$this->entityTypeManager = $entity_type_manager;
$this->entityFormBuilder = $entity_form_builder;
$this->currentUser = $current_user;
$this->commentManager = $comment_manager;
......@@ -106,7 +113,7 @@ public function renderForm($commented_entity_type_id, $commented_entity_id, $fie
'comment_type' => $comment_type_id,
'pid' => NULL,
];
$comment = $this->entityManager->getStorage('comment')->create($values);
$comment = $this->entityTypeManager->getStorage('comment')->create($values);
return $this->entityFormBuilder->getForm($comment);
}
......@@ -134,7 +141,7 @@ public function renderLinks($comment_entity_id, $view_mode, $langcode, $is_in_pr
if (!$is_in_preview) {
/** @var \Drupal\comment\CommentInterface $entity */
$entity = $this->entityManager->getStorage('comment')->load($comment_entity_id);
$entity = $this->entityTypeManager->getStorage('comment')->load($comment_entity_id);
$commented_entity = $entity->getCommentedEntity();
$links['comment'] = $this->buildLinks($entity, $commented_entity);
......
......@@ -4,7 +4,8 @@
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Session\AccountInterface;
......@@ -20,6 +21,12 @@
class CommentLinkBuilder implements CommentLinkBuilderInterface {
use StringTranslationTrait;
use DeprecatedServicePropertyTrait;
/**
* {@inheritdoc}
*/
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
/**
* Current user.
......@@ -43,11 +50,11 @@ class CommentLinkBuilder implements CommentLinkBuilderInterface {
protected $moduleHandler;
/**
* The entity manager service.
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityManager;
protected $entityTypeManager;
/**
* Constructs a new CommentLinkBuilder object.
......@@ -60,15 +67,15 @@ class CommentLinkBuilder implements CommentLinkBuilderInterface {
* Module handler service.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* String translation service.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(AccountInterface $current_user, CommentManagerInterface $comment_manager, ModuleHandlerInterface $module_handler, TranslationInterface $string_translation, EntityManagerInterface $entity_manager) {
public function __construct(AccountInterface $current_user, CommentManagerInterface $comment_manager, ModuleHandlerInterface $module_handler, TranslationInterface $string_translation, EntityTypeManagerInterface $entity_type_manager) {
$this->currentUser = $current_user;
$this->commentManager = $comment_manager;
$this->moduleHandler = $module_handler;
$this->stringTranslation = $string_translation;
$this->entityManager = $entity_manager;
$this->entityTypeManager = $entity_type_manager;
}
/**
......@@ -201,7 +208,7 @@ public function buildCommentedEntityLinks(FieldableEntityInterface $entity, arra
$entity_links['comment__' . $field_name]['#attached']['drupalSettings']['history']['lastReadTimestamps'][$entity->id()] = (int) history_read($entity->id());
$new_comments = $this->commentManager->getCountNewComments($entity);
if ($new_comments > 0) {
$page_number = $this->entityManager
$page_number = $this->entityTypeManager
->getStorage('comment')
->getNewCommentPageNumber($entity->{$field_name}->comment_count, $new_comments, $entity, $field_name);
$query = $page_number ? ['page' => $page_number] : NULL;
......
......@@ -4,8 +4,10 @@
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Session\AccountInterface;
......@@ -21,13 +23,26 @@
*/
class CommentManager implements CommentManagerInterface {
use StringTranslationTrait;
use DeprecatedServicePropertyTrait;
/**
* The entity manager service.
* {@inheritdoc}
*/
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityManager;
protected $entityFieldManager;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Whether the \Drupal\user\RoleInterface::AUTHENTICATED_ID can post comments.
......@@ -60,8 +75,8 @@ class CommentManager implements CommentManagerInterface {
/**
* Construct the CommentManager object.
*
* @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\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
......@@ -70,25 +85,32 @@ class CommentManager implements CommentManagerInterface {
* The module handler service.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager service.
*/
public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, ModuleHandlerInterface $module_handler, AccountInterface $current_user) {
$this->entityManager = $entity_manager;
public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, ModuleHandlerInterface $module_handler, AccountInterface $current_user, EntityFieldManagerInterface $entity_field_manager = NULL) {
$this->entityTypeManager = $entity_type_manager;
$this->userConfig = $config_factory->get('user.settings');
$this->stringTranslation = $string_translation;
$this->moduleHandler = $module_handler;
$this->currentUser = $current_user;
if (!$entity_field_manager) {
@trigger_error('The entity_field.manager service must be passed to CommentManager::__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 function getFields($entity_type_id) {
$entity_type = $this->entityManager->getDefinition($entity_type_id);
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) {
return [];
}
$map = $this->entityManager->getFieldMapByFieldType('comment');
$map = $this->entityFieldManager->getFieldMapByFieldType('comment');
return isset($map[$entity_type_id]) ? $map[$entity_type_id] : [];
}
......@@ -98,7 +120,7 @@ public function getFields($entity_type_id) {
public function addBodyField($comment_type_id) {
if (!FieldConfig::loadByName('comment', $comment_type_id, 'comment_body')) {
// Attaches the body field by default.
$field = $this->entityManager->getStorage('field_config')->create([
$field = $this->entityTypeManager->getStorage('field_config')->create([
'label' => 'Comment',
'bundle' => $comment_type_id,
'required' => TRUE,
......@@ -131,7 +153,7 @@ public function forbiddenMessage(EntityInterface $entity, $field_name) {
if (!isset($this->authenticatedCanPostComments)) {
// We only output a link if we are certain that users will get the
// permission to post comments by logging in.