Commit 39a57c41 authored by Sutharsan's avatar Sutharsan Committed by Sutharsan

Issue #2864259 by Sutharsan, nkoporec, Pavan B S: Replace all usages of...

Issue #2864259 by Sutharsan, nkoporec, Pavan B S: Replace all usages of deprecated EntityManagerInterface
parent f68b310b
services:
fieldblock.block_storage:
class: Drupal\fieldblock\BlockEntityStorage
arguments: ["@config.factory", "@uuid", "@language_manager", "@entity.manager"]
arguments: ["@config.factory", "@uuid", "@language_manager", "@entity_type.manager"]
......@@ -5,7 +5,7 @@ namespace Drupal\fieldblock;
use Drupal\Component\Uuid\UuidInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\Entity\ConfigEntityStorage;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
/**
......@@ -37,11 +37,11 @@ class BlockEntityStorage extends ConfigEntityStorage {
protected $languageManager;
/**
* Drupal\Core\Entity\EntityManager definition.
* Drupal\Core\Entity\EntityTypeManager definition.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityManager;
protected $entityTypeManager;
/**
* Constructor.
......@@ -52,15 +52,15 @@ class BlockEntityStorage extends ConfigEntityStorage {
* The UUID service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager) {
public function __construct(ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityTypeManagerInterface $entityTypeManager) {
$this->configFactory = $config_factory;
$this->uuidService = $uuid_service;
$this->languageManager = $language_manager;
$this->entityManager = $entity_manager;
$entity_type = $entity_manager->getDefinition('block');
$this->entityTypeManager = $entityTypeManager;
$entity_type = $entityTypeManager->getDefinition('block');
parent::__construct($entity_type, $config_factory, $uuid_service, $language_manager);
}
......
......@@ -53,7 +53,7 @@ class FieldBlockController extends ControllerBase {
protected function getDefaultEntityTypes() {
$default_types = ['node', 'user', 'taxonomy_term'];
// @todo Should there by an alter hook to allow other modules to make their entities default?
$all_types = array_keys($this->entityManager()->getDefinitions());
$all_types = array_keys($this->entityTypeManager()->getDefinitions());
// Return all default types that actually exist. "taxonomy_term" at least
// could be disabled.
return array_intersect($default_types, $all_types);
......
......@@ -3,7 +3,7 @@
namespace Drupal\fieldblock\Form;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
......@@ -17,11 +17,11 @@ use Drupal\fieldblock\BlockEntityStorage;
class FieldBlockConfigForm extends ConfigFormBase {
/**
* Drupal\Core\Entity\EntityManagerInterface definition.
* Drupal\Core\Entity\EntityTypeManagerInterface definition.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityManager;
protected $entityTypeManager;
/**
* The block entity storage.
......@@ -42,14 +42,14 @@ class FieldBlockConfigForm extends ConfigFormBase {
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Drupal\fieldblock\BlockEntityStorage $storage
* The block entity storage.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager, BlockEntityStorage $storage) {
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entityTypeManager, BlockEntityStorage $storage) {
parent::__construct($config_factory);
$this->entityManager = $entity_manager;
$this->entityTypeManager = $entityTypeManager;
$this->storage = $storage;
$this->fieldblockController = new FieldBlockController();
}
......@@ -60,7 +60,7 @@ class FieldBlockConfigForm extends ConfigFormBase {
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('entity.manager'),
$container->get('entity_type.manager'),
$container->get('fieldblock.block_storage')
);
}
......@@ -95,7 +95,7 @@ class FieldBlockConfigForm extends ConfigFormBase {
];
$orphaned_types = $this->getOrphanedEntityTypes($enabled);
$cleanup_options = [];
$entity_type_definitions = $this->entityManager->getDefinitions();
$entity_type_definitions = $this->entityTypeManager->getDefinitions();
foreach ($orphaned_types as $entity_type) {
if (isset($entity_type_definitions[$entity_type]) && $entity_type_definitions[$entity_type] instanceof ContentEntityTypeInterface) {
// This entity type still exists on the site.
......@@ -128,7 +128,7 @@ class FieldBlockConfigForm extends ConfigFormBase {
* Array of entity type definitions.
*/
protected function getAllEntityTypes() {
return array_keys($this->entityManager->getDefinitions());
return array_keys($this->entityTypeManager->getDefinitions());
}
/**
......@@ -182,7 +182,7 @@ class FieldBlockConfigForm extends ConfigFormBase {
* Array of entity type labels keyed by the entity type machine name.
*/
protected function getEntityTypeLabels() {
$definitions = $this->entityManager->getDefinitions();
$definitions = $this->entityTypeManager->getDefinitions();
$labels = [];
/** @var \Drupal\Core\Entity\EntityTypeInterface $definition */
foreach ($definitions as $definition) {
......
......@@ -5,8 +5,9 @@ namespace Drupal\fieldblock\Plugin\Block;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FormatterInterface;
......@@ -31,11 +32,18 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class FieldBlock extends BlockBase implements ContainerFactoryPluginInterface {
/**
* The entity manager.
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityManager;
protected $entityTypeManager;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* The field formatter plugin manager.
......@@ -67,16 +75,19 @@ class FieldBlock extends BlockBase implements ContainerFactoryPluginInterface {
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager
* The entity field manager.
* @param \Drupal\Core\Field\FormatterPluginManager $formatter_plugin_manager
* The field formatter plugin manager.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, FormatterPluginManager $formatter_plugin_manager, RouteMatchInterface $route_match) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager, EntityFieldManagerInterface $entityFieldManager, FormatterPluginManager $formatter_plugin_manager, RouteMatchInterface $route_match) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityManager = $entity_manager;
$this->entityTypeManager = $entityTypeManager;
$this->entityFieldManager = $entityFieldManager;
$this->formatterPluginManager = $formatter_plugin_manager;
$this->routeMatch = $route_match;
}
......@@ -88,7 +99,8 @@ class FieldBlock extends BlockBase implements ContainerFactoryPluginInterface {
return new static($configuration,
$plugin_id,
$plugin_definition,
$container->get('entity.manager'),
$container->get('entity_type.manager'),
$container->get('entity_field.manager'),
$container->get('plugin.manager.field.formatter'),
$container->get('current_route_match'));
}
......@@ -112,7 +124,7 @@ class FieldBlock extends BlockBase implements ContainerFactoryPluginInterface {
* Array of field option names keyed by their machine name.
*/
protected function getFieldOptions() {
$field_definitions = $this->entityManager->getFieldStorageDefinitions($this->getDerivativeId());
$field_definitions = $this->entityFieldManager->getFieldStorageDefinitions($this->getDerivativeId());
$options = [];
foreach ($field_definitions as $definition) {
$options[$definition->getName()] = $definition->getLabel();
......@@ -173,7 +185,7 @@ class FieldBlock extends BlockBase implements ContainerFactoryPluginInterface {
* The field storage definition used by this block.
*/
protected function getFieldStorageDefinition($field_name) {
$field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($this->getDerivativeId());
$field_storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($this->getDerivativeId());
return $field_storage_definitions[$field_name];
}
......@@ -415,7 +427,7 @@ class FieldBlock extends BlockBase implements ContainerFactoryPluginInterface {
elseif ($entity_type === 'node') {
if ($route_name == 'entity.node.revision') {
$entity_revision = $this->routeMatch->getParameter('node_revision');
$entity = $this->entityManager->getStorage('node')->loadRevision($entity_revision);
$entity = $this->entityTypeManager->getStorage('node')->loadRevision($entity_revision);
}
elseif ($route_name == 'entity.node.preview' && $this->routeMatch->getParameter('view_mode_id') === 'full') {
$entity = $this->routeMatch->getParameter('node_preview');
......
......@@ -3,7 +3,7 @@
namespace Drupal\fieldblock\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -19,20 +19,20 @@ class FieldBlockDeriver extends DeriverBase implements ContainerDeriverInterface
use StringTranslationTrait;
/**
* The entity manager.
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityManager;
protected $entityTypeManager;
/**
* Constructs a FieldBlockDeriver object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
*/
public function __construct(EntityManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
$this->entityTypeManager = $entityTypeManager;
}
/**
......@@ -40,7 +40,7 @@ class FieldBlockDeriver extends DeriverBase implements ContainerDeriverInterface
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static(
$container->get('entity.manager')
$container->get('entity_type.manager')
);
}
......@@ -49,7 +49,7 @@ class FieldBlockDeriver extends DeriverBase implements ContainerDeriverInterface
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$fb_controller = new FieldBlockController();
$definitions = $this->entityManager->getDefinitions();
$definitions = $this->entityTypeManager->getDefinitions();
foreach ($definitions as $entity_type_id => $definition) {
if ($fb_controller->isBlockableEntityType($definition)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment