diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteFormTrait.php b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteFormTrait.php index 2ec87ddfacf36bef72a43eb790e5728539ec39fe..0be6466bf37cf73aae1a89b53a65633005a3497d 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteFormTrait.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteFormTrait.php @@ -3,7 +3,7 @@ namespace Drupal\Core\Config\Entity; use Drupal\Core\Config\ConfigManagerInterface; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; /** * Lists affected configuration entities by a dependency removal. @@ -33,12 +33,12 @@ abstract protected function t($string, array $args = [], array $options = []); * or 'content' it should be a list of configuration dependency names. * @param \Drupal\Core\Config\ConfigManagerInterface $config_manager * The config manager. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. * * @see \Drupal\Core\Config\ConfigManagerInterface::getConfigEntitiesToChangeOnDependencyRemoval() */ - protected function addDependencyListsToForm(array &$form, $type, array $names, ConfigManagerInterface $config_manager, EntityManagerInterface $entity_manager) { + protected function addDependencyListsToForm(array &$form, $type, array $names, ConfigManagerInterface $config_manager, EntityTypeManagerInterface $entity_type_manager) { // Get the dependent entities. $dependent_entities = $config_manager->getConfigEntitiesToChangeOnDependencyRemoval($type, $names); $entity_types = []; @@ -55,7 +55,7 @@ protected function addDependencyListsToForm(array &$form, $type, array $names, C /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */ $entity_type_id = $entity->getEntityTypeId(); if (!isset($form['entity_updates'][$entity_type_id])) { - $entity_type = $entity_manager->getDefinition($entity_type_id); + $entity_type = $entity_type_manager->getDefinition($entity_type_id); // Store the ID and label to sort the entity types and entities later. $label = $entity_type->getLabel(); $entity_types[$entity_type_id] = $label; @@ -92,7 +92,7 @@ protected function addDependencyListsToForm(array &$form, $type, array $names, C foreach ($dependent_entities['delete'] as $entity) { $entity_type_id = $entity->getEntityTypeId(); if (!isset($form['entity_deletes'][$entity_type_id])) { - $entity_type = $entity_manager->getDefinition($entity_type_id); + $entity_type = $entity_type_manager->getDefinition($entity_type_id); // Store the ID and label to sort the entity types and entities later. $label = $entity_type->getLabel(); $entity_types[$entity_type_id] = $label; diff --git a/core/lib/Drupal/Core/Entity/EntityDeleteForm.php b/core/lib/Drupal/Core/Entity/EntityDeleteForm.php index 6dd08f2b07e8e281d92dd1fc5d7034026ecb9597..a353ab86d0ebf2f198aeee04fb5c3ea00de1a066 100644 --- a/core/lib/Drupal/Core/Entity/EntityDeleteForm.php +++ b/core/lib/Drupal/Core/Entity/EntityDeleteForm.php @@ -31,7 +31,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { if (!($entity instanceof ConfigEntityInterface)) { return $form; } - $this->addDependencyListsToForm($form, $entity->getConfigDependencyKey(), $this->getConfigNamesToDelete($entity), $this->getConfigManager(), $this->entityManager); + $this->addDependencyListsToForm($form, $entity->getConfigDependencyKey(), $this->getConfigNamesToDelete($entity), $this->getConfigManager(), $this->entityTypeManager); return $form; } diff --git a/core/modules/comment/src/CommentForm.php b/core/modules/comment/src/CommentForm.php index f3a33b8b8a513e354aa987ee14c74ba8aa17a599..952c9d139b9dee3e1f93fe727ef543ee17a0e9e3 100644 --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -249,7 +249,7 @@ protected function actions(array $form, FormStateInterface $form_state) { /* @var \Drupal\comment\CommentInterface $comment */ $comment = $this->entity; $entity = $comment->getCommentedEntity(); - $field_definition = $this->entityManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$comment->getFieldName()]; + $field_definition = $this->entityFieldManager->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle())[$comment->getFieldName()]; $preview_mode = $field_definition->getSetting('preview'); // No delete action on the comment form. diff --git a/core/modules/comment/src/CommentTypeForm.php b/core/modules/comment/src/CommentTypeForm.php index 2df24bc9b3f35c21e41da01a638ab06821a48cc0..f91bf99e34b7c756076ccd9eb55096232e365c85 100644 --- a/core/modules/comment/src/CommentTypeForm.php +++ b/core/modules/comment/src/CommentTypeForm.php @@ -2,8 +2,9 @@ namespace Drupal\comment; +use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; use Drupal\Core\Entity\EntityForm; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\language\Entity\ContentLanguageSettings; @@ -16,13 +17,21 @@ * @internal */ class CommentTypeForm extends EntityForm { + use DeprecatedServicePropertyTrait; /** - * Entity manager service. + * {@inheritdoc} + */ + protected $deprecatedProperties = [ + 'entityManager' => 'entity.manager', + ]; + + /** + * Entity type manager service. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityManager; + protected $entityTypeManager; /** * A logger instance. @@ -43,7 +52,7 @@ class CommentTypeForm extends EntityForm { */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager'), + $container->get('entity_type.manager'), $container->get('logger.factory')->get('comment'), $container->get('comment.manager') ); @@ -52,15 +61,15 @@ public static function create(ContainerInterface $container) { /** * Constructs a CommentTypeFormController * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager service. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager + * The entity type manager service. * @param \Psr\Log\LoggerInterface $logger * A logger instance. * @param \Drupal\comment\CommentManagerInterface $comment_manager * The comment manager. */ - public function __construct(EntityManagerInterface $entity_manager, LoggerInterface $logger, CommentManagerInterface $comment_manager) { - $this->entityManager = $entity_manager; + public function __construct(EntityTypeManagerInterface $entity_manager, LoggerInterface $logger, CommentManagerInterface $comment_manager) { + $this->entityTypeManager = $entity_manager; $this->logger = $logger; $this->commentManager = $comment_manager; } @@ -99,7 +108,7 @@ public function form(array $form, FormStateInterface $form_state) { if ($comment_type->isNew()) { $options = []; - foreach ($this->entityManager->getDefinitions() as $entity_type) { + foreach ($this->entityTypeManager->getDefinitions() as $entity_type) { // Only expose entities that have field UI enabled, only those can // get comment fields added in the UI. if ($entity_type->get('field_ui_base_route')) { @@ -117,7 +126,7 @@ public function form(array $form, FormStateInterface $form_state) { else { $form['target_entity_type_id_display'] = [ '#type' => 'item', - '#markup' => $this->entityManager->getDefinition($comment_type->getTargetEntityTypeId())->getLabel(), + '#markup' => $this->entityTypeManager->getDefinition($comment_type->getTargetEntityTypeId())->getLabel(), '#title' => t('Target entity type'), ]; } diff --git a/core/modules/config/src/Form/ConfigSingleExportForm.php b/core/modules/config/src/Form/ConfigSingleExportForm.php index b09ca9ab94f673547f2d5571ce421e3c9bd828f4..2f4a7df362174e020d493bbcc7d9566ac1fe9d9d 100644 --- a/core/modules/config/src/Form/ConfigSingleExportForm.php +++ b/core/modules/config/src/Form/ConfigSingleExportForm.php @@ -4,7 +4,8 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Config\StorageInterface; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormState; @@ -19,13 +20,21 @@ * @internal */ class ConfigSingleExportForm extends FormBase { + use DeprecatedServicePropertyTrait; /** - * The entity manager. + * {@inheritdoc} + */ + protected $deprecatedProperties = [ + 'entityManager' => 'entity.manager', + ]; + + /** + * The entity type manager. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityManager; + protected $entityTypeManager; /** * The config storage. @@ -44,13 +53,13 @@ class ConfigSingleExportForm extends FormBase { /** * Constructs a new ConfigSingleImportForm. * - * @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\Config\StorageInterface $config_storage * The config storage. */ - public function __construct(EntityManagerInterface $entity_manager, StorageInterface $config_storage) { - $this->entityManager = $entity_manager; + public function __construct(EntityTypeManagerInterface $entity_type_manager, StorageInterface $config_storage) { + $this->entityTypeManager = $entity_type_manager; $this->configStorage = $config_storage; } @@ -59,7 +68,7 @@ public function __construct(EntityManagerInterface $entity_manager, StorageInter */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager'), + $container->get('entity_type.manager'), $container->get('config.storage') ); } @@ -75,7 +84,7 @@ public function getFormId() { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $config_type = NULL, $config_name = NULL) { - foreach ($this->entityManager->getDefinitions() as $entity_type => $definition) { + foreach ($this->entityTypeManager->getDefinitions() as $entity_type => $definition) { if ($definition->entityClassImplements(ConfigEntityInterface::class)) { $this->definitions[$entity_type] = $definition; } @@ -143,7 +152,7 @@ public function updateConfigurationType($form, FormStateInterface $form_state) { public function updateExport($form, FormStateInterface $form_state) { // Determine the full config name for the selected config entity. if ($form_state->getValue('config_type') !== 'system.simple') { - $definition = $this->entityManager->getDefinition($form_state->getValue('config_type')); + $definition = $this->entityTypeManager->getDefinition($form_state->getValue('config_type')); $name = $definition->getConfigPrefix() . '.' . $form_state->getValue('config_name'); } // The config name is used directly for simple configuration. @@ -165,7 +174,7 @@ protected function findConfiguration($config_type) { ]; // For a given entity type, load all entities. if ($config_type && $config_type !== 'system.simple') { - $entity_storage = $this->entityManager->getStorage($config_type); + $entity_storage = $this->entityTypeManager->getStorage($config_type); foreach ($entity_storage->loadMultiple() as $entity) { $entity_id = $entity->id(); if ($label = $entity->label()) { diff --git a/core/modules/config/src/Form/ConfigSingleImportForm.php b/core/modules/config/src/Form/ConfigSingleImportForm.php index 91b6d3812bd60b2caaa037e8c24ca04af5292714..a70f50fd0e9cdc00b385783a81ba1a023058bbad 100644 --- a/core/modules/config/src/Form/ConfigSingleImportForm.php +++ b/core/modules/config/src/Form/ConfigSingleImportForm.php @@ -11,7 +11,8 @@ use Drupal\Core\Config\StorageComparer; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Config\TypedConfigManagerInterface; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleInstallerInterface; use Drupal\Core\Extension\ThemeHandlerInterface; @@ -31,12 +32,21 @@ */ class ConfigSingleImportForm extends ConfirmFormBase { + use DeprecatedServicePropertyTrait; + + /** + * {@inheritdoc} + */ + protected $deprecatedProperties = [ + 'entityManager' => 'entity.manager', + ]; + /** - * The entity manager. + * The entity type manager. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityManager; + protected $entityTypeManager; /** * The config storage. @@ -118,8 +128,8 @@ class ConfigSingleImportForm extends ConfirmFormBase { /** * Constructs a new ConfigSingleImportForm. * - * @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\Config\StorageInterface $config_storage * The config storage. * @param \Drupal\Core\Render\RendererInterface $renderer @@ -139,8 +149,8 @@ class ConfigSingleImportForm extends ConfirmFormBase { * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler * The theme handler. */ - public function __construct(EntityManagerInterface $entity_manager, StorageInterface $config_storage, RendererInterface $renderer, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, LockBackendInterface $lock, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler) { - $this->entityManager = $entity_manager; + public function __construct(EntityTypeManagerInterface $entity_type_manager, StorageInterface $config_storage, RendererInterface $renderer, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, LockBackendInterface $lock, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler) { + $this->entityTypeManager = $entity_type_manager; $this->configStorage = $config_storage; $this->renderer = $renderer; @@ -159,7 +169,7 @@ public function __construct(EntityManagerInterface $entity_manager, StorageInter */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager'), + $container->get('entity_type.manager'), $container->get('config.storage'), $container->get('renderer'), $container->get('event_dispatcher'), @@ -195,7 +205,7 @@ public function getQuestion() { $type = $this->t('simple configuration'); } else { - $definition = $this->entityManager->getDefinition($this->data['config_type']); + $definition = $this->entityTypeManager->getDefinition($this->data['config_type']); $name = $this->data['import'][$definition->getKey('id')]; $type = $definition->getLowercaseLabel(); } @@ -223,7 +233,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { } $entity_types = []; - foreach ($this->entityManager->getDefinitions() as $entity_type => $definition) { + foreach ($this->entityTypeManager->getDefinitions() as $entity_type => $definition) { if ($definition->entityClassImplements(ConfigEntityInterface::class)) { $entity_types[$entity_type] = $definition->getLabel(); } @@ -295,7 +305,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { // Validate for config entities. if ($form_state->getValue('config_type') !== 'system.simple') { - $definition = $this->entityManager->getDefinition($form_state->getValue('config_type')); + $definition = $this->entityTypeManager->getDefinition($form_state->getValue('config_type')); $id_key = $definition->getKey('id'); // If a custom entity ID is specified, override the value in the @@ -304,7 +314,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { $data[$id_key] = $form_state->getValue('custom_entity_id'); } - $entity_storage = $this->entityManager->getStorage($form_state->getValue('config_type')); + $entity_storage = $this->entityTypeManager->getStorage($form_state->getValue('config_type')); // If an entity ID was not specified, set an error. if (!isset($data[$id_key])) { $form_state->setErrorByName('import', $this->t('Missing ID key "@id_key" for this @entity_type import.', ['@id_key' => $id_key, '@entity_type' => $definition->getLabel()])); diff --git a/core/modules/field_layout/src/Form/FieldLayoutEntityFormDisplayEditForm.php b/core/modules/field_layout/src/Form/FieldLayoutEntityFormDisplayEditForm.php index 883cc9e6e26553a01b5b6d988c8ad38fdd0e601d..bb8bc221ea416a6b1e520abe4ba63da41f55ccce 100644 --- a/core/modules/field_layout/src/Form/FieldLayoutEntityFormDisplayEditForm.php +++ b/core/modules/field_layout/src/Form/FieldLayoutEntityFormDisplayEditForm.php @@ -3,6 +3,8 @@ namespace Drupal\field_layout\Form; use Drupal\Component\Plugin\PluginManagerBase; +use Drupal\Core\Entity\EntityDisplayRepositoryInterface; +use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Layout\LayoutPluginManagerInterface; use Drupal\field_ui\Form\EntityFormDisplayEditForm; @@ -26,9 +28,13 @@ class FieldLayoutEntityFormDisplayEditForm extends EntityFormDisplayEditForm { * The widget plugin manager. * @param \Drupal\Core\Layout\LayoutPluginManagerInterface $layout_plugin_manager * The layout plugin manager. + * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository + * The entity display_repository. + * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager + * The entity field manager. */ - public function __construct(FieldTypePluginManagerInterface $field_type_manager, PluginManagerBase $plugin_manager, LayoutPluginManagerInterface $layout_plugin_manager) { - parent::__construct($field_type_manager, $plugin_manager); + public function __construct(FieldTypePluginManagerInterface $field_type_manager, PluginManagerBase $plugin_manager, LayoutPluginManagerInterface $layout_plugin_manager, EntityDisplayRepositoryInterface $entity_display_repository = NULL, EntityFieldManagerInterface $entity_field_manager = NULL) { + parent::__construct($field_type_manager, $plugin_manager, $entity_display_repository, $entity_field_manager); $this->layoutPluginManager = $layout_plugin_manager; } @@ -39,7 +45,9 @@ public static function create(ContainerInterface $container) { return new static( $container->get('plugin.manager.field.field_type'), $container->get('plugin.manager.field.widget'), - $container->get('plugin.manager.core.layout') + $container->get('plugin.manager.core.layout'), + $container->get('entity_display.repository'), + $container->get('entity_field.manager') ); } diff --git a/core/modules/field_layout/src/Form/FieldLayoutEntityViewDisplayEditForm.php b/core/modules/field_layout/src/Form/FieldLayoutEntityViewDisplayEditForm.php index 3fc50e4dbfb75b1f39b22d0408d4df5d81ef4c43..628b1ae91715e3f7b974ef53a37ba4862567da48 100644 --- a/core/modules/field_layout/src/Form/FieldLayoutEntityViewDisplayEditForm.php +++ b/core/modules/field_layout/src/Form/FieldLayoutEntityViewDisplayEditForm.php @@ -3,6 +3,8 @@ namespace Drupal\field_layout\Form; use Drupal\Component\Plugin\PluginManagerBase; +use Drupal\Core\Entity\EntityDisplayRepositoryInterface; +use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Layout\LayoutPluginManagerInterface; use Drupal\field_ui\Form\EntityViewDisplayEditForm; @@ -26,9 +28,13 @@ class FieldLayoutEntityViewDisplayEditForm extends EntityViewDisplayEditForm { * The formatter plugin manager. * @param \Drupal\Core\Layout\LayoutPluginManagerInterface $layout_plugin_manager * The field layout plugin manager. + * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository + * The entity display_repository. + * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager + * The entity field manager. */ - public function __construct(FieldTypePluginManagerInterface $field_type_manager, PluginManagerBase $plugin_manager, LayoutPluginManagerInterface $layout_plugin_manager) { - parent::__construct($field_type_manager, $plugin_manager); + public function __construct(FieldTypePluginManagerInterface $field_type_manager, PluginManagerBase $plugin_manager, LayoutPluginManagerInterface $layout_plugin_manager, EntityDisplayRepositoryInterface $entity_display_repository = NULL, EntityFieldManagerInterface $entity_field_manager = NULL) { + parent::__construct($field_type_manager, $plugin_manager, $entity_display_repository, $entity_field_manager); $this->layoutPluginManager = $layout_plugin_manager; } @@ -39,7 +45,9 @@ public static function create(ContainerInterface $container) { return new static( $container->get('plugin.manager.field.field_type'), $container->get('plugin.manager.field.formatter'), - $container->get('plugin.manager.core.layout') + $container->get('plugin.manager.core.layout'), + $container->get('entity_display.repository'), + $container->get('entity_field.manager') ); } diff --git a/core/modules/field_ui/src/Form/EntityDisplayFormBase.php b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php index ebdbaed2c795afd38eaacedc70bd52d9e3e5df2f..9d45d8e6289cfd48ef0647a4266600091090fc4a 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayFormBase.php +++ b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php @@ -4,8 +4,10 @@ use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Component\Plugin\PluginManagerBase; +use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\Core\Entity\EntityWithPluginCollectionInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; @@ -34,6 +36,21 @@ abstract class EntityDisplayFormBase extends EntityForm { */ protected $pluginManager; + /** + * The entity display repository. + * + * @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface + */ + protected $entityDisplayRepository; + + + /** + * The entity field manager. + * + * @var \Drupal\Core\Entity\EntityFieldManagerInterface + */ + protected $entityFieldManager; + /** * A list of field types. * @@ -55,10 +72,24 @@ abstract class EntityDisplayFormBase extends EntityForm { * The field type manager. * @param \Drupal\Component\Plugin\PluginManagerBase $plugin_manager * The widget or formatter plugin manager. + * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface|null $entity_display_repository + * (optional) The entity display_repository. + * @param \Drupal\Core\Entity\EntityFieldManagerInterface|null $entity_field_manager + * (optional) The entity field manager. */ - public function __construct(FieldTypePluginManagerInterface $field_type_manager, PluginManagerBase $plugin_manager) { + public function __construct(FieldTypePluginManagerInterface $field_type_manager, PluginManagerBase $plugin_manager, EntityDisplayRepositoryInterface $entity_display_repository = NULL, EntityFieldManagerInterface $entity_field_manager = NULL) { $this->fieldTypes = $field_type_manager->getDefinitions(); $this->pluginManager = $plugin_manager; + if (!$entity_display_repository) { + @trigger_error('Calling EntityDisplayFormBase::__construct() with the $entity_display_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; + if (!$entity_field_manager) { + @trigger_error('Calling EntityDisplayFormBase::__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; } /** @@ -125,7 +156,7 @@ public function getRegionOptions() { */ protected function getFieldDefinitions() { $context = $this->displayContext; - return array_filter($this->entityManager->getFieldDefinitions($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle()), function (FieldDefinitionInterface $field_definition) use ($context) { + return array_filter($this->entityFieldManager->getFieldDefinitions($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle()), function (FieldDefinitionInterface $field_definition) use ($context) { return $field_definition->isDisplayConfigurable($context); }); } @@ -538,7 +569,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // If no display exists for the newly enabled view mode, initialize // it with those from the 'default' view mode, which were used so // far. - if (!$this->entityManager->getStorage($this->entity->getEntityTypeId())->load($this->entity->getTargetEntityTypeId() . '.' . $this->entity->getTargetBundle() . '.' . $mode)) { + if (!$this->entityTypeManager->getStorage($this->entity->getEntityTypeId())->load($this->entity->getTargetEntityTypeId() . '.' . $this->entity->getTargetBundle() . '.' . $mode)) { $display = $this->getEntityDisplay($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle(), 'default')->createCopy($mode); $display->save(); } @@ -730,11 +761,11 @@ public function reduceOrder($array, $a) { * @return array * An array of extra field info. * - * @see \Drupal\Core\Entity\EntityManagerInterface::getExtraFields() + * @see \Drupal\Core\Entity\EntityFieldManagerInterface::getExtraFields() */ protected function getExtraFields() { $context = $this->displayContext == 'view' ? 'display' : $this->displayContext; - $extra_fields = $this->entityManager->getExtraFields($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle()); + $extra_fields = $this->entityFieldManager->getExtraFields($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle()); return isset($extra_fields[$context]) ? $extra_fields[$context] : []; } @@ -835,7 +866,7 @@ public function getRowRegion(&$row) { protected function getDisplays() { $load_ids = []; $display_entity_type = $this->entity->getEntityTypeId(); - $entity_type = $this->entityManager->getDefinition($display_entity_type); + $entity_type = $this->entityTypeManager->getDefinition($display_entity_type); $config_prefix = $entity_type->getConfigPrefix(); $ids = $this->configFactory()->listAll($config_prefix . '.' . $this->entity->getTargetEntityTypeId() . '.' . $this->entity->getTargetBundle() . '.'); foreach ($ids as $id) { @@ -845,7 +876,7 @@ protected function getDisplays() { $load_ids[] = $config_id; } } - return $this->entityManager->getStorage($display_entity_type)->loadMultiple($load_ids); + return $this->entityTypeManager->getStorage($display_entity_type)->loadMultiple($load_ids); } /** diff --git a/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php b/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php index 67450e55bc47e19f4de8920fce6f1cd2b076c0f3..6460e619fb164f74d0abc7a5243722e49f9536ec 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php +++ b/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php @@ -27,7 +27,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t $form = parent::buildForm($form, $form_state); // Change replace_pattern to avoid undesired dots. $form['id']['#machine_name']['replace_pattern'] = '[^a-z0-9_]+'; - $definition = $this->entityManager->getDefinition($this->targetEntityTypeId); + $definition = $this->entityTypeManager->getDefinition($this->targetEntityTypeId); $form['#title'] = $this->t('Add new %label @entity-type', ['%label' => $definition->getLabel(), '@entity-type' => $this->entityType->getLowercaseLabel()]); return $form; } @@ -45,7 +45,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ protected function prepareEntity() { - $definition = $this->entityManager->getDefinition($this->targetEntityTypeId); + $definition = $this->entityTypeManager->getDefinition($this->targetEntityTypeId); if (!$definition->get('field_ui_base_route') || !$definition->hasViewBuilderClass()) { throw new NotFoundHttpException(); } diff --git a/core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php b/core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php index 128742f62117ab8904768dcc7ce9f7907c1805ec..395a2b130312525c5e44e31900817335df50b58e 100644 --- a/core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php +++ b/core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php @@ -27,7 +27,9 @@ class EntityFormDisplayEditForm extends EntityDisplayFormBase { public static function create(ContainerInterface $container) { return new static( $container->get('plugin.manager.field.field_type'), - $container->get('plugin.manager.field.widget') + $container->get('plugin.manager.field.widget'), + $container->get('entity_display.repository'), + $container->get('entity_field.manager') ); } @@ -67,14 +69,14 @@ protected function getDefaultPlugin($field_type) { * {@inheritdoc} */ protected function getDisplayModes() { - return $this->entityManager->getFormModes($this->entity->getTargetEntityTypeId()); + return $this->entityDisplayRepository->getFormModes($this->entity->getTargetEntityTypeId()); } /** * {@inheritdoc} */ protected function getDisplayModeOptions() { - return $this->entityManager->getFormModeOptions($this->entity->getTargetEntityTypeId()); + return $this->entityDisplayRepository->getFormModeOptions($this->entity->getTargetEntityTypeId()); } /** @@ -105,7 +107,7 @@ protected function getTableHeader() { * {@inheritdoc} */ protected function getOverviewUrl($mode) { - $entity_type = $this->entityManager->getDefinition($this->entity->getTargetEntityTypeId()); + $entity_type = $this->entityTypeManager->getDefinition($this->entity->getTargetEntityTypeId()); return Url::fromRoute('entity.entity_form_display.' . $this->entity->getTargetEntityTypeId() . '.form_mode', [ 'form_mode_name' => $mode, ] + FieldUI::getRouteBundleParameter($entity_type, $this->entity->getTargetBundle())); diff --git a/core/modules/field_ui/src/Form/EntityFormModeAddForm.php b/core/modules/field_ui/src/Form/EntityFormModeAddForm.php index cfcc6fb900f89e145495fb0be51147dc6308ad67..1063443ff1ce2cf10e12a83eb83fb9de60f44ce2 100644 --- a/core/modules/field_ui/src/Form/EntityFormModeAddForm.php +++ b/core/modules/field_ui/src/Form/EntityFormModeAddForm.php @@ -15,7 +15,7 @@ class EntityFormModeAddForm extends EntityDisplayModeAddForm { * {@inheritdoc} */ protected function prepareEntity() { - $definition = $this->entityManager->getDefinition($this->targetEntityTypeId); + $definition = $this->entityTypeManager->getDefinition($this->targetEntityTypeId); if (!$definition->get('field_ui_base_route') || !$definition->hasFormClasses()) { throw new NotFoundHttpException(); } diff --git a/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php b/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php index 36499af31553bca8cafa7f707977805292a02d41..cbaf65f88e9edeaf3cad8616adc7f5fd91385004 100644 --- a/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php +++ b/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php @@ -27,7 +27,9 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase { public static function create(ContainerInterface $container) { return new static( $container->get('plugin.manager.field.field_type'), - $container->get('plugin.manager.field.formatter') + $container->get('plugin.manager.field.formatter'), + $container->get('entity_display.repository'), + $container->get('entity_field.manager') ); } @@ -100,14 +102,14 @@ protected function getDefaultPlugin($field_type) { * {@inheritdoc} */ protected function getDisplayModes() { - return $this->entityManager->getViewModes($this->entity->getTargetEntityTypeId()); + return $this->entityDisplayRepository->getViewModes($this->entity->getTargetEntityTypeId()); } /** * {@inheritdoc} */ protected function getDisplayModeOptions() { - return $this->entityManager->getViewModeOptions($this->entity->getTargetEntityTypeId()); + return $this->entityDisplayRepository->getViewModeOptions($this->entity->getTargetEntityTypeId()); } /** @@ -139,7 +141,7 @@ protected function getTableHeader() { * {@inheritdoc} */ protected function getOverviewUrl($mode) { - $entity_type = $this->entityManager->getDefinition($this->entity->getTargetEntityTypeId()); + $entity_type = $this->entityTypeManager->getDefinition($this->entity->getTargetEntityTypeId()); return Url::fromRoute('entity.entity_view_display.' . $this->entity->getTargetEntityTypeId() . '.view_mode', [ 'view_mode_name' => $mode, ] + FieldUI::getRouteBundleParameter($entity_type, $this->entity->getTargetBundle())); diff --git a/core/modules/field_ui/src/Form/FieldConfigEditForm.php b/core/modules/field_ui/src/Form/FieldConfigEditForm.php index 19f386403570cc90aff0a70dc68132cfc79de093..4f953c8baf9ac7dc7af3b81bb5f2f7200d56da6d 100644 --- a/core/modules/field_ui/src/Form/FieldConfigEditForm.php +++ b/core/modules/field_ui/src/Form/FieldConfigEditForm.php @@ -147,7 +147,7 @@ protected function actions(array $form, FormStateInterface $form_state) { $actions['submit']['#value'] = $this->t('Save settings'); if (!$this->entity->isNew()) { - $target_entity_type = $this->entityManager->getDefinition($this->entity->getTargetEntityTypeId()); + $target_entity_type = $this->entityTypeManager->getDefinition($this->entity->getTargetEntityTypeId()); $route_parameters = [ 'field_config' => $this->entity->id(), ] + FieldUI::getRouteBundleParameter($target_entity_type, $this->entity->getTargetBundle()); diff --git a/core/modules/field_ui/src/Form/FieldStorageAddForm.php b/core/modules/field_ui/src/Form/FieldStorageAddForm.php index 5afd358a6782b62a70c403da3e5606c32ac04eae..fca4f86a73a7ad652237e57d235de776c6a9cfe3 100644 --- a/core/modules/field_ui/src/Form/FieldStorageAddForm.php +++ b/core/modules/field_ui/src/Form/FieldStorageAddForm.php @@ -3,7 +3,9 @@ namespace Drupal\field_ui\Form; use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; +use Drupal\Core\Entity\EntityFieldManagerInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; @@ -18,6 +20,14 @@ * @internal */ class FieldStorageAddForm extends FormBase { + use DeprecatedServicePropertyTrait; + + /** + * {@inheritdoc} + */ + protected $deprecatedProperties = [ + 'entityManager' => 'entity.manager', + ]; /** * The name of the entity type. @@ -34,11 +44,18 @@ class FieldStorageAddForm extends FormBase { protected $bundle; /** - * The entity manager. + * The entity type manager. * - * @var \Drupal\Core\Entity\EntityManager + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityManager; + protected $entityTypeManager; + + /** + * The entity field manager. + * + * @var \Drupal\Core\Entity\EntityFieldManagerInterface + */ + protected $entityFieldManager; /** * The field type plugin manager. @@ -57,17 +74,24 @@ class FieldStorageAddForm extends FormBase { /** * Constructs a new FieldStorageAddForm 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\Field\FieldTypePluginManagerInterface $field_type_plugin_manager * The field type plugin manager. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The configuration factory. + * @param \Drupal\Core\Entity\EntityFieldManagerInterface|null $entity_field_manager + * (optional) The entity field manager. */ - public function __construct(EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_plugin_manager, ConfigFactoryInterface $config_factory) { - $this->entityManager = $entity_manager; + public function __construct(EntityTypeManagerInterface $entity_type_manager, FieldTypePluginManagerInterface $field_type_plugin_manager, ConfigFactoryInterface $config_factory, EntityFieldManagerInterface $entity_field_manager = NULL) { + $this->entityTypeManager = $entity_type_manager; $this->fieldTypePluginManager = $field_type_plugin_manager; $this->configFactory = $config_factory; + if (!$entity_field_manager) { + @trigger_error('Calling FieldStorageAddForm::__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; } /** @@ -82,9 +106,10 @@ public function getFormId() { */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager'), + $container->get('entity_type.manager'), $container->get('plugin.manager.field.field_type'), - $container->get('config.factory') + $container->get('config.factory'), + $container->get('entity_field.manager') ); } @@ -293,7 +318,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $error = FALSE; $values = $form_state->getValues(); $destinations = []; - $entity_type = $this->entityManager->getDefinition($this->entityTypeId); + $entity_type = $this->entityTypeManager->getDefinition($this->entityTypeId); // Create new field. if ($values['new_storage_type']) { @@ -349,8 +374,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // Create the field storage and field. try { - $this->entityManager->getStorage('field_storage_config')->create($field_storage_values)->save(); - $field = $this->entityManager->getStorage('field_config')->create($field_values); + $this->entityTypeManager->getStorage('field_storage_config')->create($field_storage_values)->save(); + $field = $this->entityTypeManager->getStorage('field_config')->create($field_values); $field->save(); $this->configureEntityFormDisplay($values['field_name'], $widget_id, $widget_settings); @@ -379,7 +404,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $field_name = $values['existing_storage_name']; try { - $field = $this->entityManager->getStorage('field_config')->create([ + $field = $this->entityTypeManager->getStorage('field_config')->create([ 'field_name' => $field_name, 'entity_type' => $this->entityTypeId, 'bundle' => $this->bundle, @@ -477,7 +502,7 @@ protected function getExistingFieldStorageOptions() { $options = []; // Load the field_storages and build the list of options. $field_types = $this->fieldTypePluginManager->getDefinitions(); - foreach ($this->entityManager->getFieldStorageDefinitions($this->entityTypeId) as $field_name => $field_storage) { + foreach ($this->entityFieldManager->getFieldStorageDefinitions($this->entityTypeId) as $field_name => $field_storage) { // Do not show: // - non-configurable field storages, // - locked field storages, @@ -515,11 +540,11 @@ protected function getExistingFieldStorageOptions() { protected function getExistingFieldLabels(array $field_names) { // Get all the fields corresponding to the given field storage names and // this entity type. - $field_ids = $this->entityManager->getStorage('field_config')->getQuery() + $field_ids = $this->entityTypeManager->getStorage('field_config')->getQuery() ->condition('entity_type', $this->entityTypeId) ->condition('field_name', $field_names) ->execute(); - $fields = $this->entityManager->getStorage('field_config')->loadMultiple($field_ids); + $fields = $this->entityTypeManager->getStorage('field_config')->loadMultiple($field_ids); // Go through all the fields and use the label of the first encounter. $labels = []; @@ -558,7 +583,7 @@ public function fieldNameExists($value, $element, FormStateInterface $form_state // Add the field prefix. $field_name = $this->configFactory->get('field_ui.settings')->get('field_prefix') . $value; - $field_storage_definitions = $this->entityManager->getFieldStorageDefinitions($this->entityTypeId); + $field_storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($this->entityTypeId); return isset($field_storage_definitions[$field_name]); } diff --git a/core/modules/forum/src/Form/ForumForm.php b/core/modules/forum/src/Form/ForumForm.php index 46f7f8b4965c2097534e28ed8bec004cc7c77d38..73f5e8f1bfb36d84b7aa612d74255644a1e5ae06 100644 --- a/core/modules/forum/src/Form/ForumForm.php +++ b/core/modules/forum/src/Form/ForumForm.php @@ -73,7 +73,7 @@ public function buildEntity(array $form, FormStateInterface $form_state) { */ public function save(array $form, FormStateInterface $form_state) { $term = $this->entity; - $term_storage = $this->entityManager->getStorage('taxonomy_term'); + $term_storage = $this->entityTypeManager->getStorage('taxonomy_term'); $status = $term_storage->save($term); $route_name = $this->urlStub == 'container' ? 'entity.taxonomy_term.forum_edit_container_form' : 'entity.taxonomy_term.forum_edit_form'; @@ -125,7 +125,7 @@ protected function actions(array $form, FormStateInterface $form_state) { * A select form element. */ protected function forumParentSelect($tid, $title) { - $taxonomy_storage = $this->entityManager->getStorage('taxonomy_term'); + $taxonomy_storage = $this->entityTypeManager->getStorage('taxonomy_term'); $parents = $taxonomy_storage->loadParents($tid); if ($parents) { $parent = array_shift($parents); diff --git a/core/modules/node/src/Form/NodeDeleteForm.php b/core/modules/node/src/Form/NodeDeleteForm.php index 3f47a0c5fe6ed73af6f4c3c85d6a9cd4d311ab35..b02b4c62f9a154c12b1945794b8229e3ce2effd4 100644 --- a/core/modules/node/src/Form/NodeDeleteForm.php +++ b/core/modules/node/src/Form/NodeDeleteForm.php @@ -18,7 +18,7 @@ protected function getDeletionMessage() { /** @var \Drupal\node\NodeInterface $entity */ $entity = $this->getEntity(); - $node_type_storage = $this->entityManager->getStorage('node_type'); + $node_type_storage = $this->entityTypeManager->getStorage('node_type'); $node_type = $node_type_storage->load($entity->bundle())->label(); if (!$entity->isDefaultTranslation()) { diff --git a/core/modules/node/src/Form/NodePreviewForm.php b/core/modules/node/src/Form/NodePreviewForm.php index fefa24ace74b51cc91cabdd6ccacc7b350fe6a98..ca2f8d078c2e3864269513852de22704ee79f511 100644 --- a/core/modules/node/src/Form/NodePreviewForm.php +++ b/core/modules/node/src/Form/NodePreviewForm.php @@ -3,8 +3,9 @@ namespace Drupal\node\Form; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; @@ -16,13 +17,21 @@ * @internal */ class NodePreviewForm extends FormBase { + use DeprecatedServicePropertyTrait; /** - * The entity manager service. + * {@inheritdoc} + */ + protected $deprecatedProperties = [ + 'entityManager' => 'entity.manager', + ]; + + /** + * The entity display repository. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface */ - protected $entityManager; + protected $entityDisplayRepository; /** * The config factory. @@ -35,19 +44,22 @@ class NodePreviewForm extends FormBase { * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static($container->get('entity.manager'), $container->get('config.factory')); + return new static( + $container->get('entity_display.repository'), + $container->get('config.factory') + ); } /** * Constructs a new NodePreviewForm. * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager service. + * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository + * The entity display repository. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The configuration factory. */ - public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory) { - $this->entityManager = $entity_manager; + public function __construct(EntityDisplayRepositoryInterface $entity_display_repository, ConfigFactoryInterface $config_factory) { + $this->entityDisplayRepository = $entity_display_repository; $this->configFactory = $config_factory; } @@ -88,7 +100,7 @@ public function buildForm(array $form, FormStateInterface $form_state, EntityInt ]; // Always show full as an option, even if the display is not enabled. - $view_mode_options = ['full' => $this->t('Full')] + $this->entityManager->getViewModeOptionsByBundle('node', $node->bundle()); + $view_mode_options = ['full' => $this->t('Full')] + $this->entityDisplayRepository->getViewModeOptionsByBundle('node', $node->bundle()); // Unset view modes that are not used in the front end. unset($view_mode_options['default']); diff --git a/core/modules/node/src/NodeTypeForm.php b/core/modules/node/src/NodeTypeForm.php index f28056053fa6aa9bced4d763e12591742042fca8..753c5adfb6945f42a8cbfb1d6b3619b98fa95dfc 100644 --- a/core/modules/node/src/NodeTypeForm.php +++ b/core/modules/node/src/NodeTypeForm.php @@ -2,8 +2,9 @@ namespace Drupal\node; +use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; use Drupal\Core\Entity\BundleEntityFormBase; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\language\Entity\ContentLanguageSettings; @@ -15,22 +16,30 @@ * @internal */ class NodeTypeForm extends BundleEntityFormBase { + use DeprecatedServicePropertyTrait; /** - * The entity manager. + * {@inheritdoc} + */ + protected $deprecatedProperties = [ + 'entityManager' => 'entity.manager', + ]; + + /** + * The entity field manager. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityFieldManagerInterface */ - protected $entityManager; + protected $entityFieldManager; /** * Constructs the NodeTypeForm object. * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. + * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager + * The entity field manager. */ - public function __construct(EntityManagerInterface $entity_manager) { - $this->entityManager = $entity_manager; + public function __construct(EntityFieldManagerInterface $entity_field_manager) { + $this->entityFieldManager = $entity_field_manager; } /** @@ -38,7 +47,7 @@ public function __construct(EntityManagerInterface $entity_manager) { */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager') + $container->get('entity_field.manager') ); } @@ -51,18 +60,18 @@ public function form(array $form, FormStateInterface $form_state) { $type = $this->entity; if ($this->operation == 'add') { $form['#title'] = $this->t('Add content type'); - $fields = $this->entityManager->getBaseFieldDefinitions('node'); + $fields = $this->entityFieldManager->getBaseFieldDefinitions('node'); // Create a node with a fake bundle using the type's UUID so that we can // get the default values for workflow settings. // @todo Make it possible to get default values without an entity. // https://www.drupal.org/node/2318187 - $node = $this->entityManager->getStorage('node')->create(['type' => $type->uuid()]); + $node = $this->entityTypeManager->getStorage('node')->create(['type' => $type->uuid()]); } else { $form['#title'] = $this->t('Edit %label content type', ['%label' => $type->label()]); - $fields = $this->entityManager->getFieldDefinitions('node', $type->id()); + $fields = $this->entityFieldManager->getFieldDefinitions('node', $type->id()); // Create a node to get the current values for workflow settings fields. - $node = $this->entityManager->getStorage('node')->create(['type' => $type->id()]); + $node = $this->entityTypeManager->getStorage('node')->create(['type' => $type->id()]); } $form['name'] = [ @@ -234,7 +243,7 @@ public function save(array $form, FormStateInterface $form_state) { $this->logger('node')->notice('Added content type %name.', $context); } - $fields = $this->entityManager->getFieldDefinitions('node', $type->id()); + $fields = $this->entityFieldManager->getFieldDefinitions('node', $type->id()); // Update title field definition. $title_field = $fields['title']; $title_label = $form_state->getValue('title_label'); @@ -244,7 +253,7 @@ public function save(array $form, FormStateInterface $form_state) { // Update workflow options. // @todo Make it possible to get default values without an entity. // https://www.drupal.org/node/2318187 - $node = $this->entityManager->getStorage('node')->create(['type' => $type->id()]); + $node = $this->entityTypeManager->getStorage('node')->create(['type' => $type->id()]); foreach (['status', 'promote', 'sticky'] as $field_name) { $value = (bool) $form_state->getValue(['options', $field_name]); if ($node->$field_name->value != $value) { @@ -252,7 +261,7 @@ public function save(array $form, FormStateInterface $form_state) { } } - $this->entityManager->clearCachedFieldDefinitions(); + $this->entityFieldManager->clearCachedFieldDefinitions(); $form_state->setRedirectUrl($type->toUrl('collection')); } diff --git a/core/modules/system/src/Form/ModulesUninstallConfirmForm.php b/core/modules/system/src/Form/ModulesUninstallConfirmForm.php index a9783a908fca499dfb42bdf35f63e376ae9b64d8..4a66020dcca928e662726af6b1e8aa0074676f92 100644 --- a/core/modules/system/src/Form/ModulesUninstallConfirmForm.php +++ b/core/modules/system/src/Form/ModulesUninstallConfirmForm.php @@ -4,7 +4,8 @@ use Drupal\Core\Config\ConfigManagerInterface; use Drupal\Core\Config\Entity\ConfigDependencyDeleteFormTrait; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Extension\ModuleInstallerInterface; use Drupal\Core\Form\ConfirmFormBase; use Drupal\Core\Form\FormStateInterface; @@ -19,6 +20,14 @@ */ class ModulesUninstallConfirmForm extends ConfirmFormBase { use ConfigDependencyDeleteFormTrait; + use DeprecatedServicePropertyTrait; + + /** + * {@inheritdoc} + */ + protected $deprecatedProperties = [ + 'entityManager' => 'entity.manager', + ]; /** * The module installer service. @@ -42,11 +51,11 @@ class ModulesUninstallConfirmForm extends ConfirmFormBase { protected $configManager; /** - * The entity manager. + * The entity type manager. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityManager; + protected $entityTypeManager; /** * An array of modules to uninstall. @@ -64,14 +73,14 @@ class ModulesUninstallConfirmForm extends ConfirmFormBase { * The key value expirable factory. * @param \Drupal\Core\Config\ConfigManagerInterface $config_manager * The configuration manager. - * @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(ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable, ConfigManagerInterface $config_manager, EntityManagerInterface $entity_manager) { + public function __construct(ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable, ConfigManagerInterface $config_manager, EntityTypeManagerInterface $entity_type_manager) { $this->moduleInstaller = $module_installer; $this->keyValueExpirable = $key_value_expirable; $this->configManager = $config_manager; - $this->entityManager = $entity_manager; + $this->entityTypeManager = $entity_type_manager; } /** @@ -82,7 +91,7 @@ public static function create(ContainerInterface $container) { $container->get('module_installer'), $container->get('keyvalue.expirable')->get('modules_uninstall'), $container->get('config.manager'), - $container->get('entity.manager') + $container->get('entity_type.manager') ); } @@ -145,7 +154,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; // List the dependent entities. - $this->addDependencyListsToForm($form, 'module', $this->modules, $this->configManager, $this->entityManager); + $this->addDependencyListsToForm($form, 'module', $this->modules, $this->configManager, $this->entityTypeManager); return parent::buildForm($form, $form_state); } diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php index 438b219a7fc45591e75a3a76e37bd2edecd838f1..baca720fde77ddcc847ea052fed8ee41b5e8f172 100644 --- a/core/modules/taxonomy/src/TermForm.php +++ b/core/modules/taxonomy/src/TermForm.php @@ -17,9 +17,9 @@ class TermForm extends ContentEntityForm { */ public function form(array $form, FormStateInterface $form_state) { $term = $this->entity; - $vocab_storage = $this->entityManager->getStorage('taxonomy_vocabulary'); + $vocab_storage = $this->entityTypeManager->getStorage('taxonomy_vocabulary'); /** @var \Drupal\taxonomy\TermStorageInterface $taxonomy_storage */ - $taxonomy_storage = $this->entityManager->getStorage('taxonomy_term'); + $taxonomy_storage = $this->entityTypeManager->getStorage('taxonomy_term'); $vocabulary = $vocab_storage->load($term->bundle()); $parent = array_keys($taxonomy_storage->loadParents($term->id())); diff --git a/core/modules/views_ui/src/Form/BreakLockForm.php b/core/modules/views_ui/src/Form/BreakLockForm.php index 1c5e0fc55fb31b111f1d87d50db5fb9f1a16fc62..f4214da8b276de122d761b903191e0e56e3315ac 100644 --- a/core/modules/views_ui/src/Form/BreakLockForm.php +++ b/core/modules/views_ui/src/Form/BreakLockForm.php @@ -2,8 +2,9 @@ namespace Drupal\views_ui\Form; +use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait; use Drupal\Core\Entity\EntityConfirmFormBase; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\TempStore\SharedTempStoreFactory; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -14,13 +15,21 @@ * @internal */ class BreakLockForm extends EntityConfirmFormBase { + use DeprecatedServicePropertyTrait; /** - * Stores the Entity manager. + * {@inheritdoc} + */ + protected $deprecatedProperties = [ + 'entityManager' => 'entity.manager', + ]; + + /** + * Stores the entity type manager. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityManager; + protected $entityTypeManager; /** * Stores the shared tempstore. @@ -32,13 +41,13 @@ class BreakLockForm extends EntityConfirmFormBase { /** * Constructs a \Drupal\views_ui\Form\BreakLockForm object. * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The Entity manager. * @param \Drupal\Core\TempStore\SharedTempStoreFactory $temp_store_factory * The factory for the temp store object. */ - public function __construct(EntityManagerInterface $entity_manager, SharedTempStoreFactory $temp_store_factory) { - $this->entityManager = $entity_manager; + public function __construct(EntityTypeManagerInterface $entity_type_manager, SharedTempStoreFactory $temp_store_factory) { + $this->entityTypeManager = $entity_type_manager; $this->tempStore = $temp_store_factory->get('views'); } @@ -47,7 +56,7 @@ public function __construct(EntityManagerInterface $entity_manager, SharedTempSt */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager'), + $container->get('entity_type.manager'), $container->get('tempstore.shared') ); } @@ -71,7 +80,7 @@ public function getQuestion() { */ public function getDescription() { $locked = $this->tempStore->getMetadata($this->entity->id()); - $account = $this->entityManager->getStorage('user')->load($locked->getOwnerId()); + $account = $this->entityTypeManager->getStorage('user')->load($locked->getOwnerId()); $username = [ '#theme' => 'username', '#account' => $account, diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayFormBaseTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayFormBaseTest.php index 179c63e9f16a61fc7e896e1f96ceb4cac722b60a..4ef44f473fbfb126a9b150184bb4d3e992d61356 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayFormBaseTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDisplayFormBaseTest.php @@ -118,8 +118,12 @@ public function testCopyFormValuesToEntity() { }) ->shouldBeCalled(); - $form_object = new EntityViewDisplayEditForm($this->container->get('plugin.manager.field.field_type'), $this->container->get('plugin.manager.field.formatter')); - $form_object->setEntityManager($this->container->get('entity.manager')); + $form_object = new EntityViewDisplayEditForm( + $this->container->get('plugin.manager.field.field_type'), + $this->container->get('plugin.manager.field.formatter'), + $this->container->get('entity_display.repository'), + $this->container->get('entity_field.manager') + ); $form_object->setEntity($entity->reveal()); $form = [