diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index a70ad36..8a26ec0 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -66,13 +66,6 @@ class ConfigStorageController extends EntityStorageControllerBase implements Con protected $configStorage; /** - * The entity query factory. - * - * @var \Drupal\Core\Entity\Query\QueryFactory - */ - protected $entityQueryFactory; - - /** * Constructs a ConfigStorageController object. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type @@ -81,12 +74,10 @@ class ConfigStorageController extends EntityStorageControllerBase implements Con * The config factory service. * @param \Drupal\Core\Config\StorageInterface $config_storage * The config storage service. - * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query_factory - * The entity query factory. * @param \Drupal\Component\Uuid\UuidInterface $uuid_service * The UUID service. */ - public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, StorageInterface $config_storage, QueryFactory $entity_query_factory, UuidInterface $uuid_service) { + public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, StorageInterface $config_storage, UuidInterface $uuid_service) { parent::__construct($entity_type); $this->idKey = $this->entityType->getKey('id'); @@ -94,7 +85,6 @@ public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInter $this->configFactory = $config_factory; $this->configStorage = $config_storage; - $this->entityQueryFactory = $entity_query_factory; $this->uuidService = $uuid_service; } @@ -106,7 +96,6 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $entity_type, $container->get('config.factory'), $container->get('config.storage'), - $container->get('entity.query'), $container->get('uuid') ); } @@ -175,13 +164,6 @@ public function deleteRevision($revision_id) { /** * {@inheritdoc} */ - public function getQuery($conjunction = 'AND') { - return $this->entityQueryFactory->get($this->entityTypeId, $conjunction); - } - - /** - * {@inheritdoc} - */ public function getConfigPrefix() { return $this->entityType->getConfigPrefix() . '.'; } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageControllerInterface.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageControllerInterface.php index 114fa33..4ffe876 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageControllerInterface.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageControllerInterface.php @@ -31,20 +31,6 @@ public function importCreate($name, Config $new_config, Config $old_config); /** - * Returns an entity query instance. - * - * @param string $conjunction - * - AND: all of the conditions on the query need to match. - * - OR: at least one of the conditions on the query need to match. - * - * @return \Drupal\Core\Entity\Query\QueryInterface - * The query instance. - * - * @see \Drupal\Core\Entity\EntityStorageControllerInterface::getQueryServicename() - */ - public function getQuery($conjunction = 'AND'); - - /** * Updates configuration upon synchronizing configuration changes. * * This callback is invoked when configuration is synchronized between storages diff --git a/core/lib/Drupal/Core/Entity/EntityStorageControllerBase.php b/core/lib/Drupal/Core/Entity/EntityStorageControllerBase.php index 5416935..7c39f19 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageControllerBase.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageControllerBase.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Entity; use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * A base entity storage controller class. @@ -194,10 +195,17 @@ protected function buildPropertyQuery(QueryInterface $entity_query, array $value */ public function loadByProperties(array $values = array()) { // Build a query to fetch the entity IDs. - $entity_query = \Drupal::entityQuery($this->entityTypeId); + $entity_query = $this->getQuery(); $this->buildPropertyQuery($entity_query, $values); $result = $entity_query->execute(); return $result ? $this->loadMultiple($result) : array(); } + /** + * {@inheritdoc} + */ + public function getQuery($conjunction = 'AND') { + return \Drupal::entityQuery($this->getEntityTypeId(), $conjunction); + } + } diff --git a/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php index 3da5abc..2658aa2 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php @@ -155,6 +155,21 @@ public function save(EntityInterface $entity); public function getQueryServicename(); /** + * Returns an entity query instance. + * + * @param string $conjunction + * (optional) The logical operator for the query, either: + * - AND: all of the conditions on the query need to match. + * - OR: at least one of the conditions on the query need to match. + * + * @return \Drupal\Core\Entity\Query\QueryInterface + * The query instance. + * + * @see \Drupal\Core\Entity\EntityStorageControllerInterface::getQueryServicename() + */ + public function getQuery($conjunction = 'AND'); + + /** * Returns the entity type ID. * * @return string diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php index c1eda08..1ba376b 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php @@ -9,7 +9,6 @@ use Drupal\aggregator\FeedStorageControllerInterface; use Drupal\Component\Utility\UrlHelper; -use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Form\FormBase; use Symfony\Component\DependencyInjection\ContainerInterface; use Guzzle\Http\Exception\RequestException; @@ -22,13 +21,6 @@ class OpmlFeedAdd extends FormBase { /** - * The entity query factory object. - * - * @var \Drupal\Core\Entity\Query\QueryFactory - */ - protected $queryFactory; - - /** * The feed storage. * * @var \Drupal\aggregator\FeedStorageControllerInterface @@ -45,15 +37,12 @@ class OpmlFeedAdd extends FormBase { /** * Constructs a database object. * - * @param \Drupal\Core\Entity\Query\QueryFactory $query_factory - * The entity query object. * @param \Drupal\aggregator\FeedStorageControllerInterface $feed_storage * The feed storage. * @param \Guzzle\Http\ClientInterface $http_client * The Guzzle HTTP client. */ - public function __construct(QueryFactory $query_factory, FeedStorageControllerInterface $feed_storage, ClientInterface $http_client) { - $this->queryFactory = $query_factory; + public function __construct(FeedStorageControllerInterface $feed_storage, ClientInterface $http_client) { $this->feedStorageController = $feed_storage; $this->httpClient = $http_client; } @@ -63,7 +52,6 @@ public function __construct(QueryFactory $query_factory, FeedStorageControllerIn */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.query'), $container->get('entity.manager')->getStorageController('aggregator_feed'), $container->get('http_default_client') ); @@ -164,7 +152,7 @@ public function submitForm(array &$form, array &$form_state) { } // Check for duplicate titles or URLs. - $query = $this->queryFactory->get('aggregator_feed'); + $query = $this->feedStorageController->getQuery(); $condition = $query->orConditionGroup() ->condition('title', $feed['title']) ->condition('url', $feed['url']); diff --git a/core/modules/block/lib/Drupal/block/BlockFormController.php b/core/modules/block/lib/Drupal/block/BlockFormController.php index 08bf090..4ce4c81 100644 --- a/core/modules/block/lib/Drupal/block/BlockFormController.php +++ b/core/modules/block/lib/Drupal/block/BlockFormController.php @@ -11,7 +11,6 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityFormController; use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\language\ConfigurableLanguageManagerInterface; @@ -37,13 +36,6 @@ class BlockFormController extends EntityFormController { protected $storageController; /** - * The entity query factory. - * - * @var \Drupal\Core\Entity\Query\QueryFactory - */ - protected $entityQueryFactory; - - /** * The language manager. * * @var \Drupal\Core\Language\LanguageManagerInterface @@ -62,16 +54,13 @@ class BlockFormController extends EntityFormController { * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. - * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query_factory - * The entity query factory. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. */ - public function __construct(EntityManagerInterface $entity_manager, QueryFactory $entity_query_factory, LanguageManagerInterface $language_manager, ConfigFactoryInterface $config_factory) { + public function __construct(EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, ConfigFactoryInterface $config_factory) { $this->storageController = $entity_manager->getStorageController('block'); - $this->entityQueryFactory = $entity_query_factory; $this->languageManager = $language_manager; $this->configFactory = $config_factory; } @@ -82,7 +71,6 @@ public function __construct(EntityManagerInterface $entity_manager, QueryFactory public static function create(ContainerInterface $container) { return new static( $container->get('entity.manager'), - $container->get('entity.query'), $container->get('language_manager'), $container->get('config.factory') ); @@ -373,7 +361,7 @@ public function getUniqueMachineName(BlockInterface $block) { $suggestion = $block->getPlugin()->getMachineNameSuggestion(); // Get all the blocks which starts with the suggested machine name. - $query = $this->entityQueryFactory->get('block'); + $query = $this->storageController->getQuery(); $query->condition('id', $suggestion, 'CONTAINS'); $block_ids = $query->execute(); diff --git a/core/modules/block/tests/Drupal/block/Tests/BlockFormControllerTest.php b/core/modules/block/tests/Drupal/block/Tests/BlockFormControllerTest.php index 5d9f692..aa54731 100644 --- a/core/modules/block/tests/Drupal/block/Tests/BlockFormControllerTest.php +++ b/core/modules/block/tests/Drupal/block/Tests/BlockFormControllerTest.php @@ -31,7 +31,6 @@ public static function getInfo() { * @see \Drupal\block\BlockFormController::getUniqueMachineName() */ public function testGetUniqueMachineName() { - $block_storage = $this->getMock('Drupal\Core\Config\Entity\ConfigStorageControllerInterface'); $blocks = array(); $blocks['test'] = $this->getBlockMockWithMachineName('test'); @@ -39,9 +38,7 @@ public function testGetUniqueMachineName() { $blocks['other_test_1'] = $this->getBlockMockWithMachineName('other_test'); $blocks['other_test_2'] = $this->getBlockMockWithMachineName('other_test'); - $query = $this->getMockBuilder('Drupal\Core\Entity\Query\QueryInterface') - ->disableOriginalConstructor() - ->getMock(); + $query = $this->getMock('Drupal\Core\Entity\Query\QueryInterface'); $query->expects($this->exactly(5)) ->method('condition') ->will($this->returnValue($query)); @@ -50,12 +47,9 @@ public function testGetUniqueMachineName() { ->method('execute') ->will($this->returnValue(array('test', 'other_test', 'other_test_1', 'other_test_2'))); - $query_factory = $this->getMockBuilder('Drupal\Core\Entity\Query\QueryFactory') - ->disableOriginalConstructor() - ->getMock(); - $query_factory->expects($this->exactly(5)) - ->method('get') - ->with('block', 'AND') + $block_storage = $this->getMock('Drupal\Core\Config\Entity\ConfigStorageControllerInterface'); + $block_storage->expects($this->exactly(5)) + ->method('getQuery') ->will($this->returnValue($query)); $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface'); @@ -68,7 +62,7 @@ public function testGetUniqueMachineName() { $config_factory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface'); - $block_form_controller = new BlockFormController($entity_manager, $query_factory, $language_manager, $config_factory); + $block_form_controller = new BlockFormController($entity_manager, $language_manager, $config_factory); // Ensure that the block with just one other instance gets the next available // name suggestion. diff --git a/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php b/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php index 5fed1db..e2ce52a 100644 --- a/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php +++ b/core/modules/comment/lib/Drupal/comment/Form/CommentAdminOverview.php @@ -13,7 +13,6 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Datetime\Date; use Drupal\Core\Entity\EntityManager; -use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -38,13 +37,6 @@ class CommentAdminOverview extends FormBase { protected $commentStorage; /** - * The entity query service. - * - * @var \Drupal\Core\Entity\Query\QueryFactory - */ - protected $entityQuery; - - /** * Date service object. * * @var \Drupal\Core\Datetime\Date @@ -65,17 +57,14 @@ class CommentAdminOverview extends FormBase { * The entity manager service. * @param \Drupal\comment\CommentStorageControllerInterface $comment_storage * The comment storage. - * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query - * The entity query service. * @param \Drupal\Core\Datetime\Date $date * The date service. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. */ - public function __construct(EntityManager $entity_manager, CommentStorageControllerInterface $comment_storage, QueryFactory $entity_query, Date $date, ModuleHandlerInterface $module_handler) { + public function __construct(EntityManager $entity_manager, CommentStorageControllerInterface $comment_storage, Date $date, ModuleHandlerInterface $module_handler) { $this->entityManager = $entity_manager; $this->commentStorage = $comment_storage; - $this->entityQuery = $entity_query; $this->date = $date; $this->moduleHandler = $module_handler; } @@ -87,7 +76,6 @@ public static function create(ContainerInterface $container) { return new static( $container->get('entity.manager'), $container->get('entity.manager')->getStorageController('comment'), - $container->get('entity.query'), $container->get('date'), $container->get('module_handler') ); @@ -167,7 +155,7 @@ public function buildForm(array $form, array &$form_state, $type = 'new') { ), 'operations' => $this->t('Operations'), ); - $cids = $this->entityQuery->get('comment') + $cids = $this->commentStorage->getQuery() ->condition('status', $status) ->tableSort($header) ->pager(50) diff --git a/core/modules/field/lib/Drupal/field/FieldConfigStorageController.php b/core/modules/field/lib/Drupal/field/FieldConfigStorageController.php index f6d8759..7fb0866 100644 --- a/core/modules/field/lib/Drupal/field/FieldConfigStorageController.php +++ b/core/modules/field/lib/Drupal/field/FieldConfigStorageController.php @@ -54,8 +54,6 @@ class FieldConfigStorageController extends ConfigStorageController { * The config factory service. * @param \Drupal\Core\Config\StorageInterface $config_storage * The config storage service. - * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query_factory - * The entity query factory. * @param \Drupal\Component\Uuid\UuidInterface $uuid_service * The UUID service. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager @@ -65,8 +63,8 @@ class FieldConfigStorageController extends ConfigStorageController { * @param \Drupal\Core\KeyValueStore\StateInterface $state * The state key value store. */ - public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, StorageInterface $config_storage, QueryFactory $entity_query_factory, UuidInterface $uuid_service, EntityManagerInterface $entity_manager, ModuleHandler $module_handler, StateInterface $state) { - parent::__construct($entity_type, $config_factory, $config_storage, $entity_query_factory, $uuid_service); + public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, StorageInterface $config_storage, UuidInterface $uuid_service, EntityManagerInterface $entity_manager, ModuleHandler $module_handler, StateInterface $state) { + parent::__construct($entity_type, $config_factory, $config_storage, $uuid_service); $this->entityManager = $entity_manager; $this->moduleHandler = $module_handler; $this->state = $state; @@ -80,7 +78,6 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $entity_type, $container->get('config.factory'), $container->get('config.storage'), - $container->get('entity.query'), $container->get('uuid'), $container->get('entity.manager'), $container->get('module_handler'), diff --git a/core/modules/field/lib/Drupal/field/FieldInstanceConfigStorageController.php b/core/modules/field/lib/Drupal/field/FieldInstanceConfigStorageController.php index 1251b5e..d18fbf3 100644 --- a/core/modules/field/lib/Drupal/field/FieldInstanceConfigStorageController.php +++ b/core/modules/field/lib/Drupal/field/FieldInstanceConfigStorageController.php @@ -52,8 +52,6 @@ class FieldInstanceConfigStorageController extends ConfigStorageController { * The config factory service. * @param \Drupal\Core\Config\StorageInterface $config_storage * The config storage service. - * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query_factory - * The entity query factory. * @param \Drupal\Component\Uuid\UuidInterface $uuid_service * The UUID service. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager @@ -61,8 +59,8 @@ class FieldInstanceConfigStorageController extends ConfigStorageController { * @param \Drupal\Core\KeyValueStore\StateInterface $state * The state key value store. */ - public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, StorageInterface $config_storage, QueryFactory $entity_query_factory, UuidInterface $uuid_service, EntityManagerInterface $entity_manager, StateInterface $state) { - parent::__construct($entity_type, $config_factory, $config_storage, $entity_query_factory, $uuid_service); + public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, StorageInterface $config_storage, UuidInterface $uuid_service, EntityManagerInterface $entity_manager, StateInterface $state) { + parent::__construct($entity_type, $config_factory, $config_storage, $uuid_service); $this->entityManager = $entity_manager; $this->state = $state; } @@ -75,7 +73,6 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $entity_type, $container->get('config.factory'), $container->get('config.storage'), - $container->get('entity.query'), $container->get('uuid'), $container->get('entity.manager'), $container->get('state') diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php index ee9d0b8..51a7241 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php @@ -166,7 +166,7 @@ public function updateParentalStatus(EntityInterface $entity, $exclude = FALSE) // If plid == 0, there is nothing to update. if ($entity->plid) { // Check if at least one visible child exists in the table. - $query = \Drupal::entityQuery($this->entityTypeId); + $query = $this->getQuery(); $query ->condition('menu_name', $entity->menu_name) ->condition('hidden', 0) @@ -259,7 +259,7 @@ public function moveChildren(EntityInterface $entity) { * {@inheritdoc} */ public function countMenuLinks($menu_name) { - $query = \Drupal::entityQuery($this->entityTypeId); + $query = $this->getQuery(); $query ->condition('menu_name', $menu_name) ->count(); @@ -275,7 +275,7 @@ public function getParentFromHierarchy(EntityInterface $entity) { $parent = FALSE; $parent_path = substr($parent_path, 0, strrpos($parent_path, '/')); - $query = \Drupal::entityQuery($this->entityTypeId); + $query = $this->getQuery(); $query ->condition('mlid', $entity->id(), '<>') ->condition('module', 'system') diff --git a/core/modules/system/lib/Drupal/system/Form/DateFormatFormBase.php b/core/modules/system/lib/Drupal/system/Form/DateFormatFormBase.php index caae9f7..ac94508 100644 --- a/core/modules/system/lib/Drupal/system/Form/DateFormatFormBase.php +++ b/core/modules/system/lib/Drupal/system/Form/DateFormatFormBase.php @@ -14,7 +14,6 @@ use Drupal\Core\Language\Language; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Datetime\DrupalDateTime; -use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Entity\EntityFormController; /** @@ -30,13 +29,6 @@ protected $patternType; /** - * The entity query factory. - * - * @var \Drupal\Core\Entity\Query\QueryFactory - */ - protected $queryFactory; - - /** * The date service. * * @var \Drupal\Core\Datetime\Date @@ -53,18 +45,15 @@ /** * Constructs a new date format form. * - * @param \Drupal\Core\Entity\Query\QueryFactory $query_factory - * The entity query factory. * @param \Drupal\Core\Datetime\Date $date_service * The date service. * @param \Drupal\Core\Config\Entity\ConfigStorageControllerInterface $date_format_storage * The date format storage controller. */ - public function __construct(QueryFactory $query_factory, Date $date_service, ConfigStorageControllerInterface $date_format_storage) { + public function __construct(Date $date_service, ConfigStorageControllerInterface $date_format_storage) { $date = new DrupalDateTime(); $this->patternType = $date->canUseIntl() ? DrupalDateTime::INTL : DrupalDateTime::PHP; - $this->queryFactory = $query_factory; $this->dateService = $date_service; $this->dateFormatStorage = $date_format_storage; } @@ -74,7 +63,6 @@ public function __construct(QueryFactory $query_factory, Date $date_service, Con */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.query'), $container->get('date'), $container->get('entity.manager')->getStorageController('date_format') ); @@ -94,8 +82,8 @@ public static function create(ContainerInterface $container) { * TRUE if this format already exists, FALSE otherwise. */ public function exists($entity_id, array $element, array $form_state) { - return (bool) $this->queryFactory - ->get($this->entity->getEntityTypeId()) + return (bool) $this->dateFormatStorage + ->getQuery() ->condition('id', $element['#field_prefix'] . $entity_id) ->execute(); }