Issue #2969109 by martin107, andypost, kaythay, Berdir: Replace deprecated usages of entityManager in form classes

merge-requests/1119/head
Alex Pott 2019-03-10 07:34:23 +00:00
parent 7d2d9cca09
commit 2c166a50a6
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
23 changed files with 292 additions and 145 deletions

View File

@ -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 @@ trait ConfigDependencyDeleteFormTrait {
* 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 @@ trait ConfigDependencyDeleteFormTrait {
/** @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 @@ trait ConfigDependencyDeleteFormTrait {
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;

View File

@ -31,7 +31,7 @@ class EntityDeleteForm extends EntityConfirmFormBase {
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;
}

View File

@ -249,7 +249,7 @@ class CommentForm extends ContentEntityForm {
/* @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.

View File

@ -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 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* @internal
*/
class CommentTypeForm extends EntityForm {
use DeprecatedServicePropertyTrait;
/**
* Entity manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* {@inheritdoc}
*/
protected $entityManager;
protected $deprecatedProperties = [
'entityManager' => 'entity.manager',
];
/**
* Entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
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 @@ class CommentTypeForm extends EntityForm {
/**
* 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 @@ class CommentTypeForm extends EntityForm {
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 @@ class CommentTypeForm extends EntityForm {
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'),
];
}

View File

@ -4,7 +4,8 @@ namespace Drupal\config\Form;
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 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* @internal
*/
class ConfigSingleExportForm extends FormBase {
use DeprecatedServicePropertyTrait;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* {@inheritdoc}
*/
protected $entityManager;
protected $deprecatedProperties = [
'entityManager' => 'entity.manager',
];
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
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 @@ class ConfigSingleExportForm extends FormBase {
*/
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 @@ class ConfigSingleExportForm extends FormBase {
* {@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 @@ class ConfigSingleExportForm extends FormBase {
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 @@ class ConfigSingleExportForm extends FormBase {
];
// 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()) {

View File

@ -11,7 +11,8 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface;
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 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
*/
class ConfigSingleImportForm extends ConfirmFormBase {
use DeprecatedServicePropertyTrait;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* {@inheritdoc}
*/
protected $entityManager;
protected $deprecatedProperties = [
'entityManager' => 'entity.manager',
];
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
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 @@ class ConfigSingleImportForm extends ConfirmFormBase {
*/
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 @@ class ConfigSingleImportForm extends ConfirmFormBase {
$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 @@ class ConfigSingleImportForm extends ConfirmFormBase {
}
$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 @@ class ConfigSingleImportForm extends ConfirmFormBase {
// 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 @@ class ConfigSingleImportForm extends ConfirmFormBase {
$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()]));

View File

@ -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 @@ class FieldLayoutEntityFormDisplayEditForm extends EntityFormDisplayEditForm {
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')
);
}

View File

@ -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 @@ class FieldLayoutEntityViewDisplayEditForm extends EntityViewDisplayEditForm {
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')
);
}

View File

@ -4,8 +4,10 @@ namespace Drupal\field_ui\Form;
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 @@ abstract class EntityDisplayFormBase extends EntityForm {
*/
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 @@ abstract class EntityDisplayFormBase extends EntityForm {
// 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 @@ abstract class EntityDisplayFormBase extends EntityForm {
* @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 @@ abstract class EntityDisplayFormBase extends EntityForm {
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 @@ abstract class EntityDisplayFormBase extends EntityForm {
$load_ids[] = $config_id;
}
}
return $this->entityManager->getStorage($display_entity_type)->loadMultiple($load_ids);
return $this->entityTypeManager->getStorage($display_entity_type)->loadMultiple($load_ids);
}
/**

View File

@ -27,7 +27,7 @@ class EntityDisplayModeAddForm extends EntityDisplayModeFormBase {
$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 @@ class EntityDisplayModeAddForm extends EntityDisplayModeFormBase {
* {@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();
}

View File

@ -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 @@ class EntityFormDisplayEditForm extends EntityDisplayFormBase {
* {@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 @@ class EntityFormDisplayEditForm extends EntityDisplayFormBase {
* {@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()));

View File

@ -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();
}

View File

@ -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 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase {
* {@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 @@ class EntityViewDisplayEditForm extends EntityDisplayFormBase {
* {@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()));

View File

@ -147,7 +147,7 @@ class FieldConfigEditForm extends EntityForm {
$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());

View File

@ -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 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* @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 @@ class FieldStorageAddForm extends FormBase {
*/
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 @@ class FieldStorageAddForm extends FormBase {
$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 @@ class FieldStorageAddForm extends FormBase {
// 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 @@ class FieldStorageAddForm extends FormBase {
$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 @@ class FieldStorageAddForm extends FormBase {
$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 @@ class FieldStorageAddForm extends FormBase {
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 @@ class FieldStorageAddForm extends FormBase {
// 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]);
}

View File

@ -73,7 +73,7 @@ class ForumForm extends TermForm {
*/
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 @@ class ForumForm extends TermForm {
* 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);

View File

@ -18,7 +18,7 @@ class NodeDeleteForm extends ContentEntityDeleteForm {
/** @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()) {

View File

@ -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 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* @internal
*/
class NodePreviewForm extends FormBase {
use DeprecatedServicePropertyTrait;
/**
* The entity manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* {@inheritdoc}
*/
protected $entityManager;
protected $deprecatedProperties = [
'entityManager' => 'entity.manager',
];
/**
* The entity display repository.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
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 @@ class NodePreviewForm extends FormBase {
];
// 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']);

View File

@ -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 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* @internal
*/
class NodeTypeForm extends BundleEntityFormBase {
use DeprecatedServicePropertyTrait;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* {@inheritdoc}
*/
protected $entityManager;
protected $deprecatedProperties = [
'entityManager' => 'entity.manager',
];
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
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 @@ class NodeTypeForm extends BundleEntityFormBase {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager')
$container->get('entity_field.manager')
);
}
@ -51,18 +60,18 @@ class NodeTypeForm extends BundleEntityFormBase {
$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 @@ class NodeTypeForm extends BundleEntityFormBase {
$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 @@ class NodeTypeForm extends BundleEntityFormBase {
// 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 @@ class NodeTypeForm extends BundleEntityFormBase {
}
}
$this->entityManager->clearCachedFieldDefinitions();
$this->entityFieldManager->clearCachedFieldDefinitions();
$form_state->setRedirectUrl($type->toUrl('collection'));
}

View File

@ -4,7 +4,8 @@ namespace Drupal\system\Form;
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 @@ use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface;
*/
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 @@ class ModulesUninstallConfirmForm extends ConfirmFormBase {
$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 @@ class ModulesUninstallConfirmForm extends ConfirmFormBase {
];
// 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);
}

View File

@ -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()));

View File

@ -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 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* @internal
*/
class BreakLockForm extends EntityConfirmFormBase {
use DeprecatedServicePropertyTrait;
/**
* Stores the Entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* {@inheritdoc}
*/
protected $entityManager;
protected $deprecatedProperties = [
'entityManager' => 'entity.manager',
];
/**
* Stores the entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
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 @@ class BreakLockForm extends EntityConfirmFormBase {
*/
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 @@ class BreakLockForm extends EntityConfirmFormBase {
*/
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,

View File

@ -118,8 +118,12 @@ class EntityDisplayFormBaseTest extends KernelTestBase {
})
->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 = [