Commit 6018d048 authored by catch's avatar catch

Issue #2389335 by Berdir, naveenvalecha, claudiu.cristea, almaudoh, joachim,...

Issue #2389335 by Berdir, naveenvalecha, claudiu.cristea, almaudoh, joachim, jibran: Deprecate entity.query service and replace with using the entity storage's getQuery() method
parent 475e3051
......@@ -622,7 +622,7 @@ services:
arguments: ['@menu.tree_storage', '@plugin.manager.menu.link', '@router.route_provider', '@menu.active_trail', '@controller_resolver']
menu.default_tree_manipulators:
class: Drupal\Core\Menu\DefaultMenuLinkTreeManipulators
arguments: ['@access_manager', '@current_user', '@entity.query']
arguments: ['@access_manager', '@current_user', '@entity_type.manager']
menu.active_trail:
class: Drupal\Core\Menu\MenuActiveTrail
arguments: ['@plugin.manager.menu.link', '@current_route_match', '@cache.menu', '@lock']
......
......@@ -460,7 +460,7 @@ public static function httpClient() {
* The query object that can query the given entity type.
*/
public static function entityQuery($entity_type, $conjunction = 'AND') {
return static::getContainer()->get('entity.query')->get($entity_type, $conjunction);
return static::entityTypeManager()->getStorage($entity_type)->getQuery($conjunction);
}
/**
......@@ -477,7 +477,7 @@ public static function entityQuery($entity_type, $conjunction = 'AND') {
* The query object that can query the given entity type.
*/
public static function entityQueryAggregate($entity_type, $conjunction = 'AND') {
return static::getContainer()->get('entity.query')->getAggregate($entity_type, $conjunction);
return static::entityTypeManager()->getStorage($entity_type)->getAggregateQuery($conjunction);
}
/**
......
......@@ -14,8 +14,9 @@
*
* @see \Drupal\Core\Entity\EntityStorageBase::getQuery()
*
* @todo https://www.drupal.org/node/2389335 remove entity.query service and
* replace with using the entity storage's getQuery() method.
* @deprecated in Drupal 8.3.0, will be removed before Drupal 9.0.0. Use
* \Drupal\Core\Entity\EntityStorageInterface::getQuery() or
* \Drupal\Core\Entity\EntityStorageInterface::getAggregateQuery() instead.
*/
class QueryFactory implements ContainerAwareInterface {
......
......@@ -452,19 +452,16 @@
* // Simple query:
* $query = \Drupal::entityQuery('your_entity_type');
* // Or, if you have a $container variable:
* $query_service = $container->get('entity.query');
* $query = $query_service->get('your_entity_type');
* $storage = $container->get('entity_type.manager')->getStorage('your_entity_type');
* $query = $storage->getQuery();
* @endcode
* If you need aggregation, there is an aggregate query available, which
* implements \Drupal\Core\Entity\Query\QueryAggregateInterface:
* @code
* $query \Drupal::entityQueryAggregate('your_entity_type');
* // Or:
* $query = $query_service->getAggregate('your_entity_type');
* $query = $storage->getAggregateQuery('your_entity_type');
* @endcode
* Also, you should use dependency injection to get this object if
* possible; the service you need is entity.query, and its methods getQuery()
* or getAggregateQuery() will get the query object.
*
* In either case, you can then add conditions to your query, using methods
* like condition(), exists(), etc. on $query; add sorting, pager, and range
......
......@@ -4,7 +4,7 @@
use Drupal\Core\Access\AccessManagerInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\NodeInterface;
......@@ -34,11 +34,11 @@ class DefaultMenuLinkTreeManipulators {
protected $account;
/**
* The entity query factory.
* The entity type manager.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $queryFactory;
protected $entityTypeManager;
/**
* Constructs a \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators object.
......@@ -47,13 +47,13 @@ class DefaultMenuLinkTreeManipulators {
* The access manager.
* @param \Drupal\Core\Session\AccountInterface $account
* The current user.
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query factory.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(AccessManagerInterface $access_manager, AccountInterface $account, QueryFactory $query_factory) {
public function __construct(AccessManagerInterface $access_manager, AccountInterface $account, EntityTypeManagerInterface $entity_type_manager) {
$this->accessManager = $access_manager;
$this->account = $account;
$this->queryFactory = $query_factory;
$this->entityTypeManager = $entity_type_manager;
}
/**
......@@ -135,7 +135,7 @@ public function checkNodeAccess(array $tree) {
if ($node_links) {
$nids = array_keys($node_links);
$query = $this->queryFactory->get('node');
$query = $this->entityTypeManager->getStorage('node')->getQuery();
$query->condition('nid', $nids, 'IN');
// Allows admins to view all nodes, by both disabling node_access
......
......@@ -7,7 +7,6 @@
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
......@@ -38,13 +37,6 @@ class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInt
*/
protected $itemStorage;
/**
* The entity query object for feed items.
*
* @var \Drupal\Core\Entity\Query\QueryInterface
*/
protected $itemQuery;
/**
* Constructs an AggregatorFeedBlock object.
*
......@@ -58,14 +50,11 @@ class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInt
* The entity storage for feeds.
* @param \Drupal\aggregator\ItemStorageInterface $item_storage
* The entity storage for feed items.
* @param \Drupal\Core\Entity\Query\QueryInterface $item_query
* The entity query object for feed items.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, FeedStorageInterface $feed_storage, ItemStorageInterface $item_storage, QueryInterface $item_query) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, FeedStorageInterface $feed_storage, ItemStorageInterface $item_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->feedStorage = $feed_storage;
$this->itemStorage = $item_storage;
$this->itemQuery = $item_query;
}
......@@ -77,9 +66,8 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity.manager')->getStorage('aggregator_feed'),
$container->get('entity.manager')->getStorage('aggregator_item'),
$container->get('entity.query')->get('aggregator_item')
$container->get('entity_type.manager')->getStorage('aggregator_feed'),
$container->get('entity_type.manager')->getStorage('aggregator_item')
);
}
......@@ -142,7 +130,7 @@ public function blockSubmit($form, FormStateInterface $form_state) {
public function build() {
// Load the selected feed.
if ($feed = $this->feedStorage->load($this->configuration['feed'])) {
$result = $this->itemQuery
$result = $this->itemStorage->getQuery()
->condition('fid', $feed->id())
->range(0, $this->configuration['block_count'])
->sort('timestamp', 'DESC')
......
......@@ -10,7 +10,6 @@
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Form\ConfigFormBaseTrait;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
......@@ -39,13 +38,6 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor
*/
protected $configFactory;
/**
* The entity query object for feed items.
*
* @var \Drupal\Core\Entity\Query\QueryInterface
*/
protected $itemQuery;
/**
* The entity storage for items.
*
......@@ -71,17 +63,14 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor
* The plugin implementation definition.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The configuration factory object.
* @param \Drupal\Core\Entity\Query\QueryInterface $item_query
* The entity query object for feed items.
* @param \Drupal\aggregator\ItemStorageInterface $item_storage
* The entity storage for feed items.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, QueryInterface $item_query, ItemStorageInterface $item_storage, DateFormatterInterface $date_formatter) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, ItemStorageInterface $item_storage, DateFormatterInterface $date_formatter) {
$this->configFactory = $config;
$this->itemStorage = $item_storage;
$this->itemQuery = $item_query;
$this->dateFormatter = $date_formatter;
// @todo Refactor aggregator plugins to ConfigEntity so merging
// the configuration here is not needed.
......@@ -97,8 +86,7 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_id,
$plugin_definition,
$container->get('config.factory'),
$container->get('entity.query')->get('aggregator_item'),
$container->get('entity.manager')->getStorage('aggregator_item'),
$container->get('entity_type.manager')->getStorage('aggregator_item'),
$container->get('date.formatter')
);
}
......@@ -257,7 +245,7 @@ public function postProcess(FeedInterface $feed) {
if ($aggregator_clear != AGGREGATOR_CLEAR_NEVER) {
// Delete all items that are older than flush item timer.
$age = REQUEST_TIME - $aggregator_clear;
$result = $this->itemQuery
$result = $this->itemStorage->getQuery()
->condition('fid', $feed->id())
->condition('timestamp', $age, '<')
->execute();
......
......@@ -45,11 +45,14 @@ function testNewDefaultThemeBlocks() {
->set('default', $new_theme)
->save();
/** @var \Drupal\Core\Entity\EntityStorageInterface $block_storage */
$block_storage = $this->container->get('entity_type.manager')->getStorage('block');
// Ensure that the new theme has all the blocks as the previous default.
$default_block_names = $this->container->get('entity.query')->get('block')
$default_block_names = $block_storage->getQuery()
->condition('theme', $default_theme)
->execute();
$new_blocks = $this->container->get('entity.query')->get('block')
$new_blocks = $block_storage->getQuery()
->condition('theme', $new_theme)
->execute();
$this->assertTrue(count($default_block_names) == count($new_blocks), 'The new default theme has the same number of blocks as the previous theme.');
......@@ -64,7 +67,7 @@ function testNewDefaultThemeBlocks() {
// Install a hidden base theme and ensure blocks are not copied.
$base_theme = 'test_basetheme';
\Drupal::service('theme_handler')->install([$base_theme]);
$new_blocks = $this->container->get('entity.query')->get('block')
$new_blocks = $block_storage->getQuery()
->condition('theme', $base_theme)
->execute();
$this->assertTrue(empty($new_blocks), 'Installing a hidden base theme does not copy blocks from the default theme.');
......
......@@ -3,46 +3,20 @@
namespace Drupal\block_content\Form;
use Drupal\Core\Entity\EntityDeleteForm;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a confirmation form for deleting a custom block type entity.
*/
class BlockContentTypeDeleteForm extends EntityDeleteForm {
/**
* The query factory to create entity queries.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
public $queryFactory;
/**
* Constructs a query factory object.
*
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query object.
*/
public function __construct(QueryFactory $query_factory) {
$this->queryFactory = $query_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.query')
);
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$blocks = $this->queryFactory->get('block_content')->condition('type', $this->entity->id())->execute();
$blocks = $this->entityTypeManager->getStorage('block_content')->getQuery()
->condition('type', $this->entity->id())
->execute();
if (!empty($blocks)) {
$caption = '<p>' . $this->formatPlural(count($blocks), '%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', '%label is used by @count custom blocks on your site. You may not remove %label until you have removed all of the %label custom blocks.', array('%label' => $this->entity->label())) . '</p>';
$form['description'] = array('#markup' => $caption);
......
......@@ -35,5 +35,5 @@ services:
class: Drupal\book\BookUninstallValidator
tags:
- { name: module_install.uninstall_validator }
arguments: ['@book.outline_storage', '@entity.query', '@string_translation']
arguments: ['@book.outline_storage', '@entity_type.manager', '@string_translation']
lazy: true
......@@ -2,7 +2,7 @@
namespace Drupal\book;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleUninstallValidatorInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
......@@ -23,25 +23,25 @@ class BookUninstallValidator implements ModuleUninstallValidatorInterface {
protected $bookOutlineStorage;
/**
* The entity query for node.
* The entity type manager.
*
* @var \Drupal\Core\Entity\Query\QueryInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityQuery;
protected $entityTypeManager;
/**
* Constructs a new BookUninstallValidator.
*
* @param \Drupal\book\BookOutlineStorageInterface $book_outline_storage
* The book outline storage.
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query factory.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
*/
public function __construct(BookOutlineStorageInterface $book_outline_storage, QueryFactory $query_factory, TranslationInterface $string_translation) {
public function __construct(BookOutlineStorageInterface $book_outline_storage, EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
$this->bookOutlineStorage = $book_outline_storage;
$this->entityQuery = $query_factory->get('node');
$this->entityTypeManager = $entity_type_manager;
$this->stringTranslation = $string_translation;
}
......@@ -82,7 +82,7 @@ protected function hasBookOutlines() {
* TRUE if there are book nodes, FALSE otherwise.
*/
protected function hasBookNodes() {
$nodes = $this->entityQuery
$nodes = $this->entityTypeManager->getStorage('node')->getQuery()
->condition('type', 'book')
->accessCheck(FALSE)
->range(0, 1)
......
......@@ -7,7 +7,7 @@ services:
comment.manager:
class: Drupal\comment\CommentManager
arguments: ['@entity.manager', '@entity.query', '@config.factory', '@string_translation', '@url_generator', '@module_handler', '@current_user']
arguments: ['@entity.manager', '@config.factory', '@string_translation', '@url_generator', '@module_handler', '@current_user']
comment.statistics:
class: Drupal\comment\CommentStatistics
......
......@@ -7,7 +7,6 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Routing\UrlGeneratorTrait;
......@@ -32,13 +31,6 @@ class CommentManager implements CommentManagerInterface {
*/
protected $entityManager;
/**
* The entity query factory.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $queryFactory;
/**
* Whether the \Drupal\user\RoleInterface::AUTHENTICATED_ID can post comments.
*
......@@ -72,8 +64,6 @@ class CommentManager implements CommentManagerInterface {
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query factory.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
......@@ -85,9 +75,8 @@ class CommentManager implements CommentManagerInterface {
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
*/
public function __construct(EntityManagerInterface $entity_manager, QueryFactory $query_factory, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, UrlGeneratorInterface $url_generator, ModuleHandlerInterface $module_handler, AccountInterface $current_user) {
public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, UrlGeneratorInterface $url_generator, ModuleHandlerInterface $module_handler, AccountInterface $current_user) {
$this->entityManager = $entity_manager;
$this->queryFactory = $query_factory;
$this->userConfig = $config_factory->get('user.settings');
$this->stringTranslation = $string_translation;
$this->urlGenerator = $url_generator;
......@@ -212,7 +201,7 @@ public function getCountNewComments(EntityInterface $entity, $field_name = NULL,
$timestamp = ($timestamp > HISTORY_READ_LIMIT ? $timestamp : HISTORY_READ_LIMIT);
// Use the timestamp to retrieve the number of new comments.
$query = $this->queryFactory->get('comment')
$query = $this->entityManager->getStorage('comment')->getQuery()
->condition('entity_type', $entity->getEntityTypeId())
->condition('entity_id', $entity->id())
->condition('created', $timestamp, '>')
......
......@@ -5,7 +5,6 @@
use Drupal\comment\CommentManagerInterface;
use Drupal\Core\Entity\EntityDeleteForm;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Form\FormStateInterface;
use Drupal\field\Entity\FieldStorageConfig;
use Psr\Log\LoggerInterface;
......@@ -16,13 +15,6 @@
*/
class CommentTypeDeleteForm extends EntityDeleteForm {
/**
* The query factory to create entity queries.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
public $queryFactory;
/**
* The comment manager service.
*
......@@ -54,8 +46,6 @@ class CommentTypeDeleteForm extends EntityDeleteForm {
/**
* Constructs a query factory object.
*
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query object.
* @param \Drupal\comment\CommentManagerInterface $comment_manager
* The comment manager service.
* @param \Drupal\Core\Entity\EntityManager $entity_manager
......@@ -63,8 +53,7 @@ class CommentTypeDeleteForm extends EntityDeleteForm {
* @param \Psr\Log\LoggerInterface $logger
* A logger instance.
*/
public function __construct(QueryFactory $query_factory, CommentManagerInterface $comment_manager, EntityManager $entity_manager, LoggerInterface $logger) {
$this->queryFactory = $query_factory;
public function __construct(CommentManagerInterface $comment_manager, EntityManager $entity_manager, LoggerInterface $logger) {
$this->commentManager = $comment_manager;
$this->entityManager = $entity_manager;
$this->logger = $logger;
......@@ -75,7 +64,6 @@ public function __construct(QueryFactory $query_factory, CommentManagerInterface
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.query'),
$container->get('comment.manager'),
$container->get('entity.manager'),
$container->get('logger.factory')->get('comment')
......@@ -86,7 +74,9 @@ public static function create(ContainerInterface $container) {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$comments = $this->queryFactory->get('comment')->condition('comment_type', $this->entity->id())->execute();
$comments = $this->entityTypeManager->getStorage('comment')->getQuery()
->condition('comment_type', $this->entity->id())
->execute();
$entity_type = $this->entity->getTargetEntityTypeId();
$caption = '';
foreach (array_keys($this->commentManager->getFields($entity_type)) as $field_name) {
......
......@@ -4,7 +4,6 @@
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\migrate\Plugin\MigrationInterface;
......@@ -26,13 +25,6 @@ class EntityComment extends EntityContentBase {
*/
protected $state;
/**
* The entity query object.
*
* @var \Drupal\Core\Entity\Query\QueryInterface
*/
protected $entityQuery;
/**
* An array of entity IDs for the 'commented entity' keyed by entity type.
*
......@@ -61,13 +53,10 @@ class EntityComment extends EntityContentBase {
* The field type plugin manager service.
* @param \Drupal\Core\State\StateInterface $state
* The state storage object.
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
* The query object that can query the given entity type.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, StateInterface $state, QueryFactory $entity_query) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityStorageInterface $storage, array $bundles, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, StateInterface $state) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $storage, $bundles, $entity_manager, $field_type_manager);
$this->state = $state;
$this->entityQuery = $entity_query;
}
/**
......@@ -84,8 +73,7 @@ public static function create(ContainerInterface $container, array $configuratio
array_keys($container->get('entity.manager')->getBundleInfo($entity_type)),
$container->get('entity.manager'),
$container->get('plugin.manager.field.field_type'),
$container->get('state'),
$container->get('entity.query')
$container->get('state')
);
}
......
......@@ -46,7 +46,6 @@ public function testGetFields() {
$comment_manager = new CommentManager(
$entity_manager,
$this->getMockBuilder('Drupal\Core\Entity\Query\QueryFactory')->disableOriginalConstructor()->getMock(),
$this->getMock('Drupal\Core\Config\ConfigFactoryInterface'),
$this->getMock('Drupal\Core\StringTranslation\TranslationInterface'),
$this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'),
......
......@@ -3,42 +3,14 @@
namespace Drupal\config_test;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Form controller for the test config edit forms.
*/
class ConfigTestForm extends EntityForm {
/**
* The entity query.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $entityQuery;
/**
* Constructs a new ConfigTestForm.
*
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
* The entity query.
*/
public function __construct(QueryFactory $entity_query) {
$this->entityQuery = $entity_query;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.query')
);
}
/**
* {@inheritdoc}
*/
......@@ -189,7 +161,8 @@ public function save(array $form, FormStateInterface $form_state) {
public function exists($entity_id, array $element, FormStateInterface $form_state) {
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
$entity = $form_state->getFormObject()->getEntity();
return (bool) $this->entityQuery->get($entity->getEntityTypeId())
return (bool) $this->entityTypeManager->getStorage($entity->getEntityTypeId())
->getQuery()
->condition($entity->getEntityType()->getKey('id'), $entity_id)
->execute();
}
......
......@@ -3,23 +3,13 @@
namespace Drupal\field_ui\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides the generic base class for entity display mode forms.
*/
abstract class EntityDisplayModeFormBase extends EntityForm {
/**
* The entity query factory.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $queryFactory;
/**
* The entity type definition.
*
......@@ -27,42 +17,12 @@ abstract class EntityDisplayModeFormBase extends EntityForm {
*/
protected $entityType;
/**
* The entity manager.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface
*/
protected $entityManager;
/**
* Constructs a new EntityDisplayModeFormBase.
*
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query factory.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(QueryFactory $query_factory, EntityManagerInterface $entity_manager) {
$this->queryFactory = $query_factory;
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.query'),
$container->get('entity.manager')
);
}
/**
* {@inheritdoc}
*/
protected function init(FormStateInterface $form_state) {
parent::init($form_state);
$this->entityType = $this->entityManager->getDefinition($this->entity->getEntityTypeId());
$this->entityType = $this->entityTypeManager->getDefinition($this->entity->getEntityTypeId());
}
/**
......@@ -107,8 +67,9 @@ public function exists($entity_id, array $element) {
if ($entity_id == 'default') {
return TRUE;
}
return (bool) $this->queryFactory
->get($this->entity->getEntityTypeId())
return (bool) $this->entityTypeManager
->getStorage($this->entity->getEntityTypeId())
->getQuery()
->condition('id', $element['#field_prefix'] . $entity_id)
->execute();
}
......
......@@ -3,7 +3,6 @@
namespace Drupal\field_ui\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\Form\FormBase;
......@@ -46,13 +45,6 @@ class FieldStorageAddForm extends FormBase {
*/
protected $fieldTypePluginManager;
/**
* The query factory to create entity queries.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
public $queryFactory;
/**
* The configuration factory.
*
......@@ -67,15 +59,12 @@ class FieldStorageAddForm extends FormBase {
* The entity manager.
* @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_plugin_manager
* The field type plugin manager.
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query factory.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.