Commit 03a4497f authored by webchick's avatar webchick

Issue #1862300 by tim.plunkett, dawehner, YesCT: Move...

Issue #1862300 by tim.plunkett, dawehner, YesCT: Move ConfigStorageController::getQuery() to EntityStorageControllerInterface.
parent d386581c
......@@ -65,13 +65,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.
*
......@@ -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')
);
}
......@@ -172,13 +161,6 @@ public function deleteRevision($revision_id) {
return NULL;
}
/**
* {@inheritdoc}
*/
public function getQuery($conjunction = 'AND') {
return $this->entityQueryFactory->get($this->entityTypeId, $conjunction);
}
/**
* {@inheritdoc}
*/
......
......@@ -30,20 +30,6 @@ interface ConfigStorageControllerInterface extends EntityStorageControllerInterf
*/
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.
*
......
......@@ -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);
}
}
......@@ -154,6 +154,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.
*
......
......@@ -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;
......@@ -21,13 +20,6 @@
*/
class OpmlFeedAdd extends FormBase {
/**
* The entity query factory object.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $queryFactory;
/**
* The feed storage.
*
......@@ -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']);
......
......@@ -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;
......@@ -36,13 +35,6 @@ class BlockFormController extends EntityFormController {
*/
protected $storageController;
/**
* The entity query factory.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $entityQueryFactory;
/**
* The language manager.
*
......@@ -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();
......
......@@ -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.
......
......@@ -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;
......@@ -37,13 +36,6 @@ class CommentAdminOverview extends FormBase {
*/
protected $commentStorage;
/**
* The entity query service.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $entityQuery;
/**
* Date service object.
*
......@@ -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)
......
......@@ -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'),
......
......@@ -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')
......
......@@ -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')
......
......@@ -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;
/**
......@@ -29,13 +28,6 @@ abstract class DateFormatFormBase extends EntityFormController {
*/
protected $patternType;
/**
* The entity query factory.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $queryFactory;
/**
* The date service.
*
......@@ -53,18 +45,15 @@ abstract class DateFormatFormBase extends EntityFormController {
/**
* 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();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment