Commit e69e249d authored by alexpott's avatar alexpott

Issue #3023981 by Berdir, larowlan, alexpott, xjm, catch: Add @trigger_error()...

Issue #3023981 by Berdir, larowlan, alexpott, xjm, catch: Add @trigger_error() to deprecated EntityManager->EntityRepository methods
parent c8dc57ee
......@@ -369,6 +369,7 @@ public function getEntityTypeLabels($group = FALSE) {
* @see https://www.drupal.org/node/2549139
*/
public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = []) {
@trigger_error('EntityManagerInterface::getTranslationFromContext() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityRepository::getTranslationFromContext() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity.repository')->getTranslationFromContext($entity, $langcode, $context);
}
......@@ -499,6 +500,7 @@ public function clearDisplayModeInfo() {
* @see https://www.drupal.org/node/2549139
*/
public function loadEntityByUuid($entity_type_id, $uuid) {
@trigger_error('EntityManagerInterface::loadEntityByUuid() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityRepository::loadEntityByUuid() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity.repository')->loadEntityByUuid($entity_type_id, $uuid);
}
......@@ -512,6 +514,7 @@ public function loadEntityByUuid($entity_type_id, $uuid) {
* @see https://www.drupal.org/node/2549139
*/
public function loadEntityByConfigTarget($entity_type_id, $target) {
@trigger_error('EntityManagerInterface::loadEntityByConfigTarget() is deprecated in 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityRepository::loadEntityByConfigTarget() instead. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
return $this->container->get('entity.repository')->loadEntityByConfigTarget($entity_type_id, $target);
}
......
......@@ -7,6 +7,8 @@
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@trigger_error(__NAMESPACE__ . '\SelectionTrait is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. A custom constructor must be implemented instead. See https://www.drupal.org/node/3030634', E_USER_DEPRECATED);
/**
* Provides common methods and injects services for core selection handlers.
*/
......
......@@ -4,6 +4,7 @@
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Cache\Cache;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Field\FieldItemInterface;
......@@ -20,6 +21,12 @@
* @ingroup entity_api
*/
class EntityViewBuilder extends EntityHandlerBase implements EntityHandlerInterface, EntityViewBuilderInterface {
use DeprecatedServicePropertyTrait;
/**
* {@inheritdoc}
*/
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
/**
* The type of entities for which this view builder is instantiated.
......@@ -36,11 +43,18 @@ class EntityViewBuilder extends EntityHandlerBase implements EntityHandlerInterf
protected $entityType;
/**
* The entity manager service.
* The entity repository service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityManager;
protected $entityRepository;
/**
* The entity display repository.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
protected $entityDisplayRepository;
/**
* The cache bin used to store the render cache.
......@@ -77,19 +91,26 @@ class EntityViewBuilder extends EntityHandlerBase implements EntityHandlerInterf
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Theme\Registry $theme_registry
* The theme registry.
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
* The entity display repository.
*/
public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, Registry $theme_registry = NULL) {
public function __construct(EntityTypeInterface $entity_type, EntityRepositoryInterface $entity_repository, LanguageManagerInterface $language_manager, Registry $theme_registry = NULL, EntityDisplayRepositoryInterface $entity_display_repository = NULL) {
$this->entityTypeId = $entity_type->id();
$this->entityType = $entity_type;
$this->entityManager = $entity_manager;
$this->entityRepository = $entity_repository;
$this->languageManager = $language_manager;
$this->themeRegistry = $theme_registry ?: \Drupal::service('theme.registry');
if (!$entity_display_repository) {
@trigger_error('Calling EntityViewBuilder::__construct() with the $entity_repository argument is supported in drupal:8.7.0 and will be 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;
}
/**
......@@ -98,9 +119,10 @@ public function __construct(EntityTypeInterface $entity_type, EntityManagerInter
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$entity_type,
$container->get('entity.manager'),
$container->get('entity.repository'),
$container->get('language_manager'),
$container->get('theme.registry')
$container->get('theme.registry'),
$container->get('entity_display.repository')
);
}
......@@ -132,7 +154,7 @@ public function viewMultiple(array $entities = [], $view_mode = 'full', $langcod
foreach ($entities as $key => $entity) {
// Ensure that from now on we are dealing with the proper translation
// object.
$entity = $this->entityManager->getTranslationFromContext($entity, $langcode);
$entity = $this->entityRepository->getTranslationFromContext($entity, $langcode);
// Set build defaults.
$build_list[$key] = $this->getBuildDefaults($entity, $view_mode);
......@@ -418,7 +440,7 @@ protected function isViewModeCacheable($view_mode) {
// The 'default' is not an actual view mode.
return TRUE;
}
$view_modes_info = $this->entityManager->getViewModes($this->entityTypeId);
$view_modes_info = $this->entityDisplayRepository->getViewModes($this->entityTypeId);
return !empty($view_modes_info[$view_mode]['cache']);
}
......
......@@ -4,10 +4,13 @@
use Drupal\Component\Utility\Html;
use Drupal\Core\Database\Query\AlterableInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginBase;
use Drupal\Core\Entity\EntityReferenceSelection\SelectionTrait;
use Drupal\Core\Entity\EntityReferenceSelection\SelectionWithAutocreateInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
......@@ -15,6 +18,7 @@
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\EntityOwnerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Default plugin implementation of the Entity Reference Selection plugin.
......@@ -37,20 +41,118 @@
* )
*/
class DefaultSelection extends SelectionPluginBase implements ContainerFactoryPluginInterface, SelectionWithAutocreateInterface {
use DeprecatedServicePropertyTrait;
use SelectionTrait {
// PHP 5.5.9 gets confused between SelectionPluginBase::__construct() and
// SelectionTrait::__construct() that's why we are renaming the
// SelectionTrait::__construct() to avoid the confusion.
// @todo Remove this in https://www.drupal.org/node/2670966.
SelectionTrait::__construct as private initialize;
/**
* {@inheritdoc}
*/
protected $deprecatedProperties = ['entityManager' => 'entity.manager'];
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityTypeManager;
/**
* The entity field manager service.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* Entity type bundle info service.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
public $entityTypeBundleInfo;
/**
* The entity repository.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityRepository;
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* Constructs a new DefaultSelection object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity manager service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* 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.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle info service.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, AccountInterface $current_user, EntityFieldManagerInterface $entity_field_manager = NULL, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, EntityRepositoryInterface $entity_repository = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->moduleHandler = $module_handler;
$this->currentUser = $current_user;
if (!$entity_field_manager) {
@trigger_error('Calling DefaultSelection::__construct() with the $entity_field_manager argument is supported in drupal:8.7.0 and will be 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_type_bundle_info) {
@trigger_error('Calling DefaultSelection::__construct() with the $entity_type_bundle_info argument is supported in drupal:8.7.0 and will be required before drupal:9.0.0. See https://www.drupal.org/node/2549139.', E_USER_DEPRECATED);
$entity_type_bundle_info = \Drupal::service('entity_type.bundle.info');
}
$this->entityTypeBundleInfo = $entity_type_bundle_info;
if (!$entity_repository) {
@trigger_error('Calling DefaultSelection::__construct() with the $entity_repository argument is supported in drupal:8.7.0 and will be 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;
}
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, AccountInterface $current_user) {
$this->initialize($configuration, $plugin_id, $plugin_definition, $entity_manager, $module_handler, $current_user);
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager'),
$container->get('module_handler'),
$container->get('current_user'),
$container->get('entity_field.manager'),
$container->get('entity_type.bundle.info'),
$container->get('entity.repository')
);
}
/**
......@@ -79,8 +181,8 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
$configuration = $this->getConfiguration();
$entity_type_id = $configuration['target_type'];
$entity_type = $this->entityManager->getDefinition($entity_type_id);
$bundles = $this->entityManager->getBundleInfo($entity_type_id);
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
$bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id);
if ($entity_type->hasKey('bundle')) {
$bundle_options = [];
......@@ -122,7 +224,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
if ($entity_type->entityClassImplements(FieldableEntityInterface::class)) {
$fields = [];
foreach (array_keys($bundles) as $bundle) {
$bundle_fields = array_filter($this->entityManager->getFieldDefinitions($entity_type_id, $bundle), function ($field_definition) {
$bundle_fields = array_filter($this->entityFieldManager->getFieldDefinitions($entity_type_id, $bundle), function ($field_definition) {
return !$field_definition->isComputed();
});
foreach ($bundle_fields as $field_name => $field_definition) {
......@@ -245,10 +347,10 @@ public function getReferenceableEntities($match = NULL, $match_operator = 'CONTA
}
$options = [];
$entities = $this->entityManager->getStorage($target_type)->loadMultiple($result);
$entities = $this->entityTypeManager->getStorage($target_type)->loadMultiple($result);
foreach ($entities as $entity_id => $entity) {
$bundle = $entity->bundle();
$options[$bundle][$entity_id] = Html::escape($this->entityManager->getTranslationFromContext($entity)->label());
$options[$bundle][$entity_id] = Html::escape($this->entityRepository->getTranslationFromContext($entity)->label());
}
return $options;
......@@ -271,7 +373,7 @@ public function validateReferenceableEntities(array $ids) {
$result = [];
if ($ids) {
$target_type = $this->configuration['target_type'];
$entity_type = $this->entityManager->getDefinition($target_type);
$entity_type = $this->entityTypeManager->getDefinition($target_type);
$query = $this->buildEntityQuery();
$result = $query
->condition($entity_type->getKey('id'), $ids, 'IN')
......@@ -285,11 +387,11 @@ public function validateReferenceableEntities(array $ids) {
* {@inheritdoc}
*/
public function createNewEntity($entity_type_id, $bundle, $label, $uid) {
$entity_type = $this->entityManager->getDefinition($entity_type_id);
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
$bundle_key = $entity_type->getKey('bundle');
$label_key = $entity_type->getKey('label');
$entity = $this->entityManager->getStorage($entity_type_id)->create([
$entity = $this->entityTypeManager->getStorage($entity_type_id)->create([
$bundle_key => $bundle,
$label_key => $label,
]);
......@@ -330,9 +432,9 @@ public function validateReferenceableNewEntities(array $entities) {
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$configuration = $this->getConfiguration();
$target_type = $configuration['target_type'];
$entity_type = $this->entityManager->getDefinition($target_type);
$entity_type = $this->entityTypeManager->getDefinition($target_type);
$query = $this->entityManager->getStorage($target_type)->getQuery();
$query = $this->entityTypeManager->getStorage($target_type)->getQuery();
// If 'target_bundles' is NULL, all bundles are referenceable, no further
// conditions are needed.
......
......@@ -49,7 +49,7 @@ protected function getEntitiesToView(EntityReferenceFieldItemListInterface $item
// Set the entity in the correct language for display.
if ($entity instanceof TranslatableInterface) {
$entity = \Drupal::entityManager()->getTranslationFromContext($entity, $langcode);
$entity = \Drupal::service('entity.repository')->getTranslationFromContext($entity, $langcode);
}
$access = $this->checkAccess($entity);
......
......@@ -473,7 +473,7 @@ public static function calculateDependencies(FieldDefinitionInterface $field_def
if ($default_value = $field_definition->getDefaultValueLiteral()) {
foreach ($default_value as $value) {
if (is_array($value) && isset($value['target_uuid'])) {
$entity = \Drupal::entityManager()->loadEntityByUuid($target_entity_type->id(), $value['target_uuid']);
$entity = \Drupal::service('entity.repository')->loadEntityByUuid($target_entity_type->id(), $value['target_uuid']);
// If the entity does not exist do not create the dependency.
// @see \Drupal\Core\Field\EntityReferenceFieldItemList::processDefaultValue()
if ($entity) {
......@@ -522,7 +522,7 @@ public static function onDependencyRemoval(FieldDefinitionInterface $field_defin
if ($default_value = $field_definition->getDefaultValueLiteral()) {
foreach ($default_value as $key => $value) {
if (is_array($value) && isset($value['target_uuid'])) {
$entity = $entity_manager->loadEntityByUuid($target_entity_type->id(), $value['target_uuid']);
$entity = \Drupal::service('entity.repository')->loadEntityByUuid($target_entity_type->id(), $value['target_uuid']);
// @see \Drupal\Core\Field\EntityReferenceFieldItemList::processDefaultValue()
if ($entity && isset($dependencies[$entity->getConfigDependencyKey()][$entity->getConfigDependencyName()])) {
unset($default_value[$key]);
......
......@@ -2,11 +2,14 @@
namespace Drupal\aggregator;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\EntityViewBuilder;
use Drupal\Core\Config\Config;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Theme\Registry;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -15,21 +18,42 @@
*/
class FeedViewBuilder extends EntityViewBuilder {
/**
* The 'aggregator.settings' config.
*
* @var \Drupal\Core\Config\Config
*/
protected $config;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a new FeedViewBuilder.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Config\Config $config
* The 'aggregator.settings' config.
* @param \Drupal\Core\Theme\Registry $theme_registry
* The theme registry.
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
* The entity display repository.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, Config $config) {
parent::__construct($entity_type, $entity_manager, $language_manager);
public function __construct(EntityTypeInterface $entity_type, EntityRepositoryInterface $entity_repository, LanguageManagerInterface $language_manager, Config $config, Registry $theme_registry, EntityDisplayRepositoryInterface $entity_display_repository, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($entity_type, $entity_repository, $language_manager, $theme_registry, $entity_display_repository);
$this->config = $config;
$this->entityTypeManager = $entity_type_manager;
}
/**
......@@ -38,9 +62,12 @@ public function __construct(EntityTypeInterface $entity_type, EntityManagerInter
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$entity_type,
$container->get('entity.manager'),
$container->get('entity.repository'),
$container->get('language_manager'),
$container->get('config.factory')->get('aggregator.settings')
$container->get('config.factory')->get('aggregator.settings'),
$container->get('theme.registry'),
$container->get('entity_display.repository'),
$container->get('entity_type.manager')
);
}
......@@ -58,11 +85,11 @@ public function buildComponents(array &$build, array $entities, array $displays,
// When in summary view mode, respect the list_max setting.
$limit = $view_mode == 'summary' ? $this->config->get('source.list_max') : 20;
// Retrieve the items attached to this feed.
$items = $this->entityManager
$items = $this->entityTypeManager
->getStorage('aggregator_item')
->loadByFeed($entity->id(), $limit);
$build[$id]['items'] = $this->entityManager
$build[$id]['items'] = $this->entityTypeManager
->getViewBuilder('aggregator_item')
->viewMultiple($items, $view_mode, $entity->language()->getId());
......
......@@ -6,58 +6,18 @@
use Drupal\Core\Block\TitleBlockPluginInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityViewBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\ContextAwarePluginInterface;
use Drupal\Core\Render\Element;
use Drupal\block\Entity\Block;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a Block view builder.
*/
class BlockViewBuilder extends EntityViewBuilder {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs a new BlockViewBuilder.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler) {
parent::__construct($entity_type, $entity_manager, $language_manager);
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$entity_type,
$container->get('entity.manager'),
$container->get('language_manager'),
$container->get('module_handler')
);
}
/**
* {@inheritdoc}
*/
......
......@@ -98,7 +98,7 @@ public function setUp() {
'target_bundles' => ['spiffy' => 'spiffy'],
'sort' => ['field' => '_none'],
];
$this->selectionHandler = new TestSelection($configuration, '', '', $this->container->get('entity.manager'), $this->container->get('module_handler'), \Drupal::currentUser());
$this->selectionHandler = new TestSelection($configuration, '', '', $this->container->get('entity_type.manager'), $this->container->get('module_handler'), \Drupal::currentUser(), \Drupal::service('entity_field.manager'), \Drupal::service('entity_type.bundle.info'), \Drupal::service('entity.repository'));
// Setup the 3 expectation cases.
$this->expectations = [
......
......@@ -3,12 +3,15 @@
namespace Drupal\comment;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\EntityViewBuilder;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Theme\Registry;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -23,21 +26,35 @@ class CommentViewBuilder extends EntityViewBuilder {
*/
protected $currentUser;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a new CommentViewBuilder.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Theme\Registry $theme_registry
* The theme registry.
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
* The entity display repository.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, AccountInterface $current_user) {
parent::__construct($entity_type, $entity_manager, $language_manager);
public function __construct(EntityTypeInterface $entity_type, EntityRepositoryInterface $entity_repository, LanguageManagerInterface $language_manager, AccountInterface $current_user, Registry $theme_registry, EntityDisplayRepositoryInterface $entity_display_repository, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($entity_type, $entity_repository, $language_manager, $theme_registry, $entity_display_repository);
$this->currentUser = $current_user;
$this->entityTypeManager = $entity_type_manager;
}
/**
......@@ -46,9 +63,12 @@ public function __construct(EntityTypeInterface $entity_type, EntityManagerInter
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$entity_type,
$container->get('entity.manager'),
$container->get('entity.repository'),
$container->get('language_manager'),
$container->get('current_user')
$container->get('current_user'),
$container->get('theme.registry'),
$container->get('entity_display.repository'),
$container->get('entity_type.manager')
);
}
......@@ -92,7 +112,7 @@ public function buildComponents(array &$build, array $entities, array $displays,
foreach ($entities as $entity) {
$uids[] = $entity->getOwnerId();
}
$this->entityManager->getStorage('user')->loadMultiple(array_unique($uids));
$this->entityTypeManager->getStorage('user')->loadMultiple(array_unique($uids));
parent::buildComponents($build, $entities, $displays, $view_mode);
......
......@@ -38,7 +38,7 @@ public function getItems(ResultRow $values) {
}
foreach ($entity_ids_per_type as $type => $ids) {
$this->loadedCommentedEntities[$type] = $this->entityManager->getStorage($type)->loadMultiple($ids);
$this->loadedCommentedEntities[$type] = $this->entityTypeManager->getStorage($type)->loadMultiple($ids);
}
}
......
......@@ -4,6 +4,8 @@
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\comment\Plugin\views\field\CommentBulkForm;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Tests\UnitTestCase;
/**
......@@ -46,12 +48,14 @@ public function testConstructor() {
->method('loadMultiple')
->will($this->returnValue($actions));
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
$entity_manager->expects($this->once())
$entity_type_manager = $this->createMock(EntityTypeManagerInterface::class);
$entity_type_manager->expects($this->once())
->method('getStorage')
->with('action')
->will($this->returnValue($entity_storage));
$entity_repository = $this->createMock(EntityRepositoryInterface::class);
$language_manager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
$messenger = $this->getMock('Drupal\Core\Messenger\MessengerInterface');
......@@ -86,7 +90,7 @@ public function testConstructor() {
$definition['title'] = '';
$options = [];
$comment_bulk_form = new CommentBulkForm([], 'comment_bulk_form', $definition, $entity_manager, $language_manager, $messenger);
$comment_bulk_form = new CommentBulkForm([], 'comment_bulk_form', $definition, $entity_type_manager, $language_manager, $messenger, $entity_repository);
$comment_bulk_form->init($executable, $display, $options);
$this->assertAttributeEquals(array_slice($actions, 0, -1, TRUE), 'actions', $comment_bulk_form);
......
......@@ -37,7 +37,7 @@ public function assertConfigEntityImport(ConfigEntityInterface $entity) {
// should recreate everything as necessary.
$entity->delete();
$this->configImporter()->reset()->import();
$imported_entity = \Drupal::entityManager()->loadEntityByUuid($entity_type_id, $entity_uuid);
$imported_entity = \Drupal::service('entity.repository')->loadEntityByUuid($entity_type_id, $entity_uuid);
$this->assertIdentical($original_data, $imported_entity->toArray());