diff --git a/fieldblock.services.yml b/fieldblock.services.yml index b665432113477c9e244361ad82ed1b943ca98a75..d013561739cbacb808ee91f1cf5128dbfa209069 100644 --- a/fieldblock.services.yml +++ b/fieldblock.services.yml @@ -1,4 +1,4 @@ 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"] diff --git a/src/BlockEntityStorage.php b/src/BlockEntityStorage.php index 1f16132d66f1dd1930c8ca0067b111e437829c99..10120529e0e11f93006b038fd692950c19a7ff15 100644 --- a/src/BlockEntityStorage.php +++ b/src/BlockEntityStorage.php @@ -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); } diff --git a/src/Controller/FieldBlockController.php b/src/Controller/FieldBlockController.php index 056cf9f11d455814b875d4725406b2f52a86ffdd..e67ccbf444abf170095e959cedf9056fc9f88a8f 100644 --- a/src/Controller/FieldBlockController.php +++ b/src/Controller/FieldBlockController.php @@ -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); diff --git a/src/Form/FieldBlockConfigForm.php b/src/Form/FieldBlockConfigForm.php index a4e5ab0a51f712db8e421074ada2333257a7d41e..094e473553b57da2133a9b00700caf0a0255c2fc 100644 --- a/src/Form/FieldBlockConfigForm.php +++ b/src/Form/FieldBlockConfigForm.php @@ -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) { diff --git a/src/Plugin/Block/FieldBlock.php b/src/Plugin/Block/FieldBlock.php index 4f2ec88b8a2dd014b482c5ce0adfb9ed27635069..d1a2db3c479e0b0417ef04bb8c8d4df82a14d22f 100644 --- a/src/Plugin/Block/FieldBlock.php +++ b/src/Plugin/Block/FieldBlock.php @@ -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'); diff --git a/src/Plugin/Derivative/FieldBlockDeriver.php b/src/Plugin/Derivative/FieldBlockDeriver.php index 866d2a3cc8c7412d43a843472467da4fe9d8db0d..8ac358845a902a9968900d438c83c03721d5aefa 100644 --- a/src/Plugin/Derivative/FieldBlockDeriver.php +++ b/src/Plugin/Derivative/FieldBlockDeriver.php @@ -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)) {