Commit bea3588b authored by alexpott's avatar alexpott

Issue #1957148 by damiankloip | Berdir: Replace entity_query() with Drupal::entityQuery().

parent 2fbb2642
......@@ -735,40 +735,6 @@ function entity_get_render_display(EntityInterface $entity, $view_mode) {
return $display;
}
/**
* Returns the entity query object for this entity type.
*
* @param $entity_type
* The entity type, e.g. node, for which the query object should be
* returned.
* @param $conjunction
* AND if all conditions in the query need to apply, OR if any of them is
* enough. Optional, defaults to AND.
*
* @return \Drupal\Core\Entity\Query\QueryInterface
* The query object that can query the given entity type.
*/
function entity_query($entity_type, $conjunction = 'AND') {
return drupal_container()->get('entity.query')->get($entity_type, $conjunction);
}
/**
* Returns the entity query aggregate object for this entity type.
*
* @param $entity_type
* The entity type, e.g. node, for which the query object should be
* returned.
* @param $conjunction
* AND if all conditions in the query need to apply, OR if any of them is
* enough. Optional, defaults to AND.
*
* @return \Drupal\Core\Entity\Query\QueryInterface
* The query object that can query the given entity type.
*/
function entity_query_aggregate($entity_type, $conjunction = 'AND') {
return drupal_container()->get('entity.query')->getAggregate($entity_type, $conjunction);
}
/**
* Generic access callback for entity pages.
*
......
......@@ -1276,7 +1276,7 @@ function menu_tree_page_data($menu_name, $max_depth = NULL, $only_active_trail =
// Collect all the links set to be expanded, and then add all of
// their children to the list as well.
do {
$query = entity_query('menu_link')
$query = Drupal::entityQuery('menu_link')
->condition('menu_name', $menu_name)
->condition('expanded', 1)
->condition('has_children', 1)
......@@ -1371,7 +1371,7 @@ function _menu_build_tree($menu_name, array $parameters = array()) {
}
if (!isset($trees[$tree_cid])) {
$query = entity_query('menu_link');
$query = Drupal::entityQuery('menu_link');
for ($i = 1; $i <= MENU_MAX_DEPTH; $i++) {
$query->sort('p' . $i, 'ASC');
}
......@@ -2830,7 +2830,7 @@ function _menu_navigation_links_rebuild($menu) {
}
// Find any item whose router path does not exist any more.
$query = entity_query('menu_link')
$query = Drupal::entityQuery('menu_link')
->condition('router_path', $paths, 'NOT IN')
->condition('external', 0)
->condition('updated', 0)
......@@ -2857,7 +2857,7 @@ function _menu_navigation_links_rebuild($menu) {
function menu_load_links($menu_name) {
$links = array();
$query = entity_query('menu_link')
$query = Drupal::entityQuery('menu_link')
->condition('menu_name', $menu_name)
// Order by weight so as to be helpful for menus that are only one level
// deep.
......
......@@ -292,6 +292,23 @@ public static function entityQuery($entity_type, $conjunction = 'AND') {
return static::$container->get('entity.query')->get($entity_type, $conjunction);
}
/**
* Returns the entity query aggregate object for this entity type.
*
* @param $entity_type
* The entity type, e.g. node, for which the query object should be
* returned.
* @param $conjunction
* AND if all conditions in the query need to apply, OR if any of them is
* enough. Optional, defaults to AND.
*
* @return \Drupal\Core\Entity\Query\QueryInterface
* The query object that can query the given entity type.
*/
public static function entityQueryAggregate($entity_type, $conjunction = 'AND') {
return static::$container->get('entity.query')->getAggregate($entity_type, $conjunction);
}
/**
* Returns the flood instance.
*
......
......@@ -290,7 +290,7 @@ public function deleteRevision($revision_id) {
*/
public function loadByProperties(array $values = array()) {
// Build a query to fetch the entity IDs.
$entity_query = entity_query($this->entityType);
$entity_query = \Drupal::entityQuery($this->entityType);
$this->buildPropertyQuery($entity_query, $values);
$result = $entity_query->execute();
return $result ? $this->load($result) : array();
......
......@@ -37,7 +37,7 @@ public function getEntityType();
* For example, to find all entities containing both the Turkish 'merhaba'
* and the Polish 'siema' within a 'greetings' text field:
* @code
* $entity_ids = entity_query($entity_type)
* $entity_ids = Drupal::entityQuery($entity_type)
* ->condition('greetings', 'merhaba', '=', 'tr');
* ->condition('greetings.value', 'siema', '=', 'pl');
* ->execute();
......@@ -198,7 +198,7 @@ public function conditionGroupFactory($conjunction = 'AND');
* field containing 'shape' and 'color' columns. To find all drawings
* containing both a red triangle and a blue circle:
* @code
* $query = entity_query('drawing');
* $query = Drupal::entityQuery('drawing');
* $group = $query->andConditionGroup()
* ->condition('figures.color', 'red')
* ->condition('figures.shape', 'triangle');
......@@ -221,7 +221,7 @@ public function andConditionGroup();
* containing 'building_type' and 'color' columns. To find all green and
* red bikesheds:
* @code
* $query = entity_query('map');
* $query = Drupal::entityQuery('map');
* $group = $query->orConditionGroup()
* ->condition('attributes.color', 'red')
* ->condition('attributes.color', 'green');
......
......@@ -67,7 +67,7 @@ function custom_block_type_delete_form($form, &$form_state, CustomBlockType $blo
$message = t('Are you sure you want to delete %label?', array('%label' => $block_type->label()));
$blocks = entity_query('custom_block')->condition('type', $block_type->id())->execute();
$blocks = Drupal::entityQuery('custom_block')->condition('type', $block_type->id())->execute();
if (!empty($blocks)) {
drupal_set_title($message, PASS_THROUGH);
$caption = '<p>' . format_plural(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' => $block_type->label())) . '</p>';
......
......@@ -57,7 +57,7 @@ public function testHookCustomBlockLoad() {
// Now, as part of the same page request, load a set of custom_blocks that contain
// both basic and other bundle, and make sure the parameters passed to
// custom_block_test_custom_block_load() are correctly updated.
$custom_blocks = entity_load_multiple('custom_block', entity_query('custom_block')->execute(), TRUE);
$custom_blocks = entity_load_multiple('custom_block', \Drupal::entityQuery('custom_block')->execute(), TRUE);
$loaded_custom_block = end($custom_blocks);
$this->assertEqual($loaded_custom_block->custom_block_test_loaded_ids, array(
$custom_block1->id->value,
......
......@@ -39,7 +39,7 @@ public function testPageEdit() {
$this->drupalPost('block/add/basic', $edit, t('Save'));
// Check that the block exists in the database.
$blocks = entity_query('custom_block')->condition('info', $edit['info'])->execute();
$blocks = \Drupal::entityQuery('custom_block')->condition('info', $edit['info'])->execute();
$block = entity_load('custom_block', reset($blocks));
$this->assertTrue($block, 'Custom block found in database.');
......
......@@ -267,7 +267,7 @@ public function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$target_type = $this->field['settings']['target_type'];
$entity_info = entity_get_info($target_type);
$query = entity_query($target_type);
$query = \Drupal::entityQuery($target_type);
if (!empty($this->instance['settings']['handler_settings']['target_bundles'])) {
$query->condition($entity_info['entity_keys']['bundle'], $this->instance['settings']['handler_settings']['target_bundles'], 'IN');
}
......
......@@ -78,7 +78,7 @@ public function testAutoCreate() {
$new_title = $this->randomName();
// Assert referenced node does not exist.
$base_query = entity_query('node');
$base_query = \Drupal::entityQuery('node');
$base_query
->condition('type', $this->referenced_type)
->condition('title', $new_title);
......@@ -100,7 +100,7 @@ public function testAutoCreate() {
$referenced_nid = key($result);
// Assert the referenced node is associated with referencing node.
$result = entity_query('node')
$result = \Drupal::entityQuery('node')
->condition('type', $this->referencing_type)
->execute();
......
......@@ -854,7 +854,7 @@ function field_purge_batch($batch_size) {
// Retrieve all deleted field instances. We cannot use field_info_instances()
// because that function does not return deleted instances.
$instances = field_read_instances(array('deleted' => 1), array('include_deleted' => 1));
$factory = drupal_container()->get('entity.query');
$factory = Drupal::service('entity.query');
$info = entity_get_info();
foreach ($instances as $instance) {
$entity_type = $instance['entity_type'];
......
......@@ -1005,7 +1005,7 @@ function field_get_items(EntityInterface $entity, $field_name, $langcode = NULL)
function field_has_data($field) {
$field = field_info_field_by_id($field['id']);
$columns = array_keys($field['columns']);
$factory = drupal_container()->get('entity.query');
$factory = Drupal::service('entity.query');
foreach ($field['bundles'] as $entity_type => $bundle) {
// Entity Query throws an exception if there is no base table.
$entity_info = entity_get_info($entity_type);
......
......@@ -151,7 +151,7 @@ function testDeleteFieldInstance() {
$bundle = reset($this->bundles);
$field = reset($this->fields);
$field_name = $field['field_name'];
$factory = drupal_container()->get('entity.query');
$factory = \Drupal::service('entity.query');
// There are 10 entities of this bundle.
$found = $factory->get('test_entity')
......@@ -223,7 +223,7 @@ function testPurgeInstance() {
field_purge_batch($batch_size);
// There are $count deleted entities left.
$found = entity_query('test_entity')
$found = \Drupal::entityQuery('test_entity')
->condition('fttype', $bundle)
->condition($field['field_name'] . '.deleted', 1)
->execute();
......
......@@ -549,7 +549,7 @@ private function getStandardMenuLink() {
$mlid = 0;
// Retrieve menu link id of the Log out menu link, which will always be on
// the front page.
$query = entity_query('menu_link')
$query = \Drupal::entityQuery('menu_link')
->condition('module', 'system')
->condition('router_path', 'user/logout');
$result = $query->execute();
......
......@@ -74,7 +74,7 @@ function menu_overview_form($form, &$form_state) {
$form['#attached']['css'] = array(drupal_get_path('module', 'menu') . '/menu.admin.css');
$links = array();
$query = entity_query('menu_link')
$query = Drupal::entityQuery('menu_link')
->condition('menu_name', $form_state['menu']->id());
for ($i = 1; $i <= MENU_MAX_DEPTH; $i++) {
$query->sort('p' . $i, 'ASC');
......@@ -379,7 +379,7 @@ function menu_edit_menu_name_exists($value) {
$custom_exists = entity_load('menu', $value);
// 'menu-' is added to the menu name to avoid name-space conflicts.
$value = 'menu-' . $value;
$link_exists = entity_query('menu_link')->condition('menu_name', $value)->range(0,1)->count()->execute();
$link_exists = Drupal::entityQuery('menu_link')->condition('menu_name', $value)->range(0,1)->count()->execute();
return $custom_exists || $link_exists;
}
......
......@@ -210,7 +210,7 @@ function menu_enable() {
$link->link_title = $menu->label();
$link->link_path = 'admin/structure/menu/manage/' . $menu->id();
$query = entity_query('menu_link')
$query = Drupal::entityQuery('menu_link')
->condition('link_path', $link->link_path)
->condition('plid', $link->plid);
$result = $query->execute();
......@@ -467,7 +467,7 @@ function menu_node_save(EntityInterface $node) {
*/
function menu_node_predelete(EntityInterface $node) {
// Delete all menu module links that point to this node.
$query = entity_query('menu_link')
$query = Drupal::entityQuery('menu_link')
->condition('link_path', 'node/' . $node->nid)
->condition('module', 'menu');
$result = $query->execute();
......@@ -490,7 +490,7 @@ function menu_node_prepare(EntityInterface $node) {
// Give priority to the default menu
$type_menus = variable_get('menu_options_' . $node->type, array('main' => 'main'));
if (in_array($menu_name, $type_menus)) {
$query = entity_query('menu_link')
$query = Drupal::entityQuery('menu_link')
->condition('link_path', 'node/' . $node->nid)
->condition('menu_name', $menu_name)
->condition('module', 'menu')
......@@ -502,7 +502,7 @@ function menu_node_prepare(EntityInterface $node) {
}
// Check all allowed menus if a link does not exist in the default menu.
if (!$mlid && !empty($type_menus)) {
$query = entity_query('menu_link')
$query = Drupal::entityQuery('menu_link')
->condition('link_path', 'node/' . $node->nid)
->condition('menu_name', array_values($type_menus), 'IN')
->condition('module', 'menu')
......
......@@ -349,7 +349,7 @@ protected function updateParentalStatus(EntityInterface $entity, $exclude = FALS
// If plid == 0, there is nothing to update.
if ($entity->plid) {
// Check if at least one visible child exists in the table.
$query = entity_query($this->entityType);
$query = \Drupal::entityQuery($this->entityType);
$query
->condition('menu_name', $entity->menu_name)
->condition('hidden', 0)
......@@ -433,7 +433,7 @@ protected function findParent(EntityInterface $entity, array $parent_candidates
$parent = FALSE;
$parent_path = substr($parent_path, 0, strrpos($parent_path, '/'));
$query = entity_query($this->entityType);
$query = \Drupal::entityQuery($this->entityType);
$query
->condition('mlid', $entity->id(), '<>')
->condition('module', 'system')
......@@ -569,7 +569,7 @@ protected function moveChildren(EntityInterface $entity) {
* The unique name of a menu.
*/
public function countMenuLinks($menu_name) {
$query = entity_query($this->entityType);
$query = \Drupal::entityQuery($this->entityType);
$query
->condition('menu_name', $menu_name)
->count();
......
......@@ -89,7 +89,7 @@ function menu_link_delete_multiple(array $mlids, $force = FALSE, $prevent_repare
$controller = drupal_container()->get('plugin.manager.entity')
->getStorageController('menu_link');
if (!$force) {
$entity_query = entity_query('menu_link');
$entity_query = Drupal::entityQuery('menu_link');
$group = $entity_query->orConditionGroup()
->condition('module', 'system', '<>')
->condition('updated', 0, '<>');
......@@ -178,7 +178,7 @@ function menu_link_maintain($module, $op, $link_path, $link_title = NULL) {
break;
case 'delete':
$result = entity_query('menu_link')->condition('link_path', $link_path)->execute();
$result = Drupal::entityQuery('menu_link')->condition('link_path', $link_path)->execute();
if (!empty($result)) {
menu_link_delete_multiple($result);
}
......
......@@ -154,7 +154,7 @@ function node_access_test_page() {
function node_access_entity_test_page() {
$output = '';
try {
$result = entity_query('node')
$result = Drupal::entityQuery('node')
->condition('body.value', 'A', 'STARTS_WITH')
->execute();
if (!empty($result)) {
......
......@@ -389,7 +389,7 @@ function options_field_update_forbid($field, $prior_field, $has_data) {
function _options_values_in_use($field, $values) {
if ($values) {
$field = field_info_field_by_id($field['id']);
$factory = drupal_container()->get('entity.query');
$factory = Drupal::service('entity.query');
foreach ($field['bundles'] as $entity_type => $bundle) {
$result = $factory->get($entity_type)
->condition($field['field_name'] . '.value', $values)
......
......@@ -115,7 +115,7 @@ function testEnableModulesInstallContainer() {
$this->installSchema('node', array('node_type', 'node'));
// Perform an entity query against node.
$query = entity_query('node');
$query = \Drupal::entityQuery('node');
// Disable node access checks, since User module is not enabled.
$query->accessCheck(FALSE);
$query->condition('nid', 1);
......
......@@ -533,12 +533,12 @@ function testEntityNGRollback() {
if (Database::getConnection()->supportsTransactions()) {
// Check that the block does not exist in the database.
$ids = entity_query('entity_test')->condition('name', 'fail_insert')->execute();
$ids = \Drupal::entityQuery('entity_test')->condition('name', 'fail_insert')->execute();
$this->assertTrue(empty($ids), 'Transactions supported, and entity not found in database.');
}
else {
// Check that the block exists in the database.
$ids = entity_query('entity_test')->condition('name', 'fail_insert')->execute();
$ids = \Drupal::entityQuery('entity_test')->condition('name', 'fail_insert')->execute();
$this->assertFalse(empty($ids), 'Transactions not supported, and entity found in database.');
}
}
......
......@@ -115,7 +115,7 @@ public function setUp() {
$entity->save();
$this->entities[] = $entity;
}
$this->factory = drupal_container()->get('entity.query');
$this->factory = \Drupal::service('entity.query');
}
/**
......
......@@ -126,7 +126,7 @@ function setUp() {
}
$this->figures = $figures;
$this->greetings = $greetings;
$this->factory = drupal_container()->get('entity.query');
$this->factory = \Drupal::service('entity.query');
}
/**
......@@ -459,7 +459,7 @@ protected function assertBundleOrder($order) {
* The tags and metadata should propogate to the SQL query object.
*/
function testMetaData() {
$query = entity_query('test_entity');
$query = \Drupal::entityQuery('test_entity');
$query
->addTag('efq_metadata_test')
->addMetaData('foo', 'bar')
......
......@@ -317,7 +317,7 @@ protected function assertMultilingualProperties($entity_type) {
// Test property conditions and orders with multiple languages in the same
// query.
$query = entity_query($entity_type);
$query = \Drupal::entityQuery($entity_type);
$group = $query->andConditionGroup()
->condition('user_id', $properties[$default_langcode]['user_id'], '=', $default_langcode)
->condition('name', $properties[$default_langcode]['name'], '=', $default_langcode);
......@@ -332,7 +332,7 @@ protected function assertMultilingualProperties($entity_type) {
$field_value = $this->randomString();
$entity->getTranslation($langcode)->set($this->field_name, array(array('value' => $field_value)));
$entity->save();
$query = entity_query($entity_type);
$query = \Drupal::entityQuery($entity_type);
$default_langcode_group = $query->andConditionGroup()
->condition('user_id', $properties[$default_langcode]['user_id'], '=', $default_langcode)
->condition('name', $properties[$default_langcode]['name'], '=', $default_langcode);
......
......@@ -365,7 +365,7 @@ function testMenuHierarchy() {
*/
function testMenuHidden() {
// Verify links for one dynamic argument.
$query = entity_query('menu_link')
$query = \Drupal::entityQuery('menu_link')
->condition('router_path', 'menu-test/hidden/menu', 'STARTS_WITH')
->sort('router_path');
$result = $query->execute();
......@@ -417,7 +417,7 @@ function testMenuHidden() {
$this->assertEqual($link['plid'], $plid, format_string('%path plid @link_plid is equal to @plid.', array('%path' => $link['router_path'], '@link_plid' => $link['plid'], '@plid' => $plid)));
// Verify links for two dynamic arguments.
$query = entity_query('menu_link')
$query = \Drupal::entityQuery('menu_link')
->condition('router_path', 'menu-test/hidden/block', 'STARTS_WITH')
->sort('router_path');
$result = $query->execute();
......
......@@ -23,7 +23,7 @@ function system_admin_config_page() {
$blocks = array();
if ($system_link = entity_load_multiple_by_properties('menu_link', array('link_path' => 'admin/config', 'module' => 'system'))) {
$system_link = reset($system_link);
$query = entity_query('menu_link')
$query = Drupal::entityQuery('menu_link')
->condition('link_path', 'admin/help', '<>')
->condition('menu_name', $system_link->menu_name)
->condition('plid', $system_link->id())
......
......@@ -37,7 +37,7 @@ function testTaxonomyEfq() {
$term = $this->createTerm($this->vocabulary);
$terms[$term->tid] = $term;
}
$result = entity_query('taxonomy_term')->execute();
$result = \Drupal::entityQuery('taxonomy_term')->execute();
sort($result);
$this->assertEqual(array_keys($terms), $result, 'Taxonomy terms were retrieved by entity query.');
$tid = reset($result);
......@@ -57,7 +57,7 @@ function testTaxonomyEfq() {
$terms2[$term->tid] = $term;
}
$result = entity_query('taxonomy_term')
$result = \Drupal::entityQuery('taxonomy_term')
->condition('vid', $vocabulary2->id())
->execute();
sort($result);
......
......@@ -504,7 +504,7 @@ function toolbar_toolbar() {
*/
function toolbar_get_menu_tree() {
$tree = array();
$query = entity_query('menu_link')
$query = Drupal::entityQuery('menu_link')
->condition('menu_name', 'admin')
->condition('module', 'system')
->condition('link_path', 'admin');
......
......@@ -118,7 +118,7 @@ function tour_preprocess_page(&$variables) {
$path_alias = drupal_strtolower(drupal_container()->get('path.alias_manager')->getPathAlias($path));
foreach ($tours as $tour_id => $tour) {
// @todo replace this with an entity_query() that does path matching when
// @todo Replace this with an entity query that does path matching when
// http://drupal.org/node/1918768 lands.
$pages = implode("\n", $tour->getPaths());
if (!drupal_match_path($path_alias, $pages) && (($path == $path_alias) || drupal_match_path($path, $pages))) {
......
......@@ -475,7 +475,7 @@ function translation_entity_translatable_batch($translatable, $field_name, &$con
foreach ($entity_types as $entity_type) {
// How many entities will need processing?
$query = entity_query($entity_type);
$query = Drupal::entityQuery($entity_type);
$count = $query
->exists($query_field)
->count()
......@@ -500,7 +500,7 @@ function translation_entity_translatable_batch($translatable, $field_name, &$con
$info = entity_get_info($entity_type);
$offset = $context['sandbox']['progress_entity_type'][$entity_type];
$query = entity_query($entity_type);
$query = Drupal::entityQuery($entity_type);
$result = $query
->exists($query_field)
->sort($info['entity_keys']['id'])
......
......@@ -1060,7 +1060,7 @@ function views_get_all_views() {
* Returns an array of all enabled views, as fully loaded $view objects.
*/
function views_get_enabled_views() {
$query = drupal_container()->get('entity.query')->get('view')
$query = Drupal::entityQuery('view')
->condition('status', TRUE)
->execute();
......@@ -1071,7 +1071,7 @@ function views_get_enabled_views() {
* Returns an array of all disabled views, as fully loaded $view objects.
*/
function views_get_disabled_views() {
$query = drupal_container()->get('entity.query')->get('view')
$query = Drupal::entityQuery('view')
->condition('status', FALSE)
->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