diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 4822628..d87793f 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -573,3 +573,17 @@ function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL) { function entity_view_multiple(array $entities, $view_mode, $langcode = NULL) { return entity_render_controller(reset($entities)->entityType())->viewMultiple($entities, $view_mode, $langcode); } + +/** + * 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. + */ +function entity_query($entity_type, $conjunction = 'AND') { + return drupal_container()->get('entity.query')->get($entity_type, $conjunction); +} diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index 9b44a5d..d5d6e8b 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -376,7 +376,7 @@ protected function invokeHook($hook, EntityInterface $entity) { } /** - * Implements Drupal\Core\Entity\EntityStorageControllerInterface:: + * Implements Drupal\Core\Entity\EntityStorageControllerInterface::getQueryServicename(). */ public function getQueryServicename() { throw new \LogicException('Querying config entities is not supported.'); diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php index 3b6ab93..d496ea0 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php @@ -265,7 +265,7 @@ public function deleteRevision($revision_id) { */ public function loadByProperties(array $values = array()) { // Build a query to fetch the entity IDs. - $entity_query = drupal_container()->get('entity.query')->get($this->entityType); + $entity_query = entity_query($this->entityType); $this->buildPropertyQuery($entity_query, $values); $result = $entity_query->execute(); return $result ? $this->load($result) : array(); @@ -274,7 +274,7 @@ public function loadByProperties(array $values = array()) { /** * Builds an entity query. * - * @param \Drupal\Core\Entity\Query\EntityQueryInterface $entity_query + * @param \Drupal\Core\Entity\Query\QueryInterface $entity_query * EntityQuery instance. * @param array $values * An associative array of properties of the entity, where the keys are the diff --git a/core/lib/Drupal/Core/Entity/Query/ConditionBase.php b/core/lib/Drupal/Core/Entity/Query/ConditionBase.php index b170c8d..0284a64 100644 --- a/core/lib/Drupal/Core/Entity/Query/ConditionBase.php +++ b/core/lib/Drupal/Core/Entity/Query/ConditionBase.php @@ -44,11 +44,12 @@ public function count() { /** * Implements Drupal\Core\Entity\Query\ConditionInterface::compile(). */ - public function condition($field, $value = NULL, $operator = NULL) { + public function condition($field, $value = NULL, $operator = NULL, $langcode = NULL) { $this->conditions[] = array( 'field' => $field, 'value' => $value, 'operator' => $operator, + 'langcode' => $langcode, ); return $this; diff --git a/core/lib/Drupal/Core/Entity/Query/ConditionInterface.php b/core/lib/Drupal/Core/Entity/Query/ConditionInterface.php index 388b00a..3cd7671 100644 --- a/core/lib/Drupal/Core/Entity/Query/ConditionInterface.php +++ b/core/lib/Drupal/Core/Entity/Query/ConditionInterface.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Entity\Query; /** - * + * Defines the entity query condition interface. */ interface ConditionInterface { @@ -32,24 +32,26 @@ public function getConjunction(); public function count(); /** - * @param $field - * @param null $value - * @param null $operator + * @param string $field + * @param mixed $value + * @param string $operator + * @param string $langcode * @return ConditionInterface */ - public function condition($field, $value = NULL, $operator = NULL); + public function condition($field, $value = NULL, $operator = NULL, $langcode = NULL); /** * @param $field + * @param string $langcode * @return ConditionInterface */ - public function exists($field); + public function exists($field, $langcode = NULL); /** * @param string $field * @return ConditionInterface; */ - public function notExists($field); + public function notExists($field, $langcode = NULL); /** * @return array diff --git a/core/lib/Drupal/Core/Entity/Query/QueryBase.php b/core/lib/Drupal/Core/Entity/Query/QueryBase.php index 6927665..c76a65c 100644 --- a/core/lib/Drupal/Core/Entity/Query/QueryBase.php +++ b/core/lib/Drupal/Core/Entity/Query/QueryBase.php @@ -93,24 +93,24 @@ public function getEntityType() { /** * Implements Drupal\Core\Entity\Query\QueryInterface::condition(). */ - public function condition($property, $value = NULL, $operator = NULL) { - $this->condition->condition($property, $value, $operator); + public function condition($property, $value = NULL, $operator = NULL, $langcode = NULL) { + $this->condition->condition($property, $value, $operator, $langcode); return $this; } /** * Implements Drupal\Core\Entity\Query\QueryInterface::exists(). */ - public function exists($property) { - $this->condition->exists($property); + public function exists($property, $langcode = NULL) { + $this->condition->exists($property, $langcode); return $this; } /** * Implements Drupal\Core\Entity\Query\QueryInterface::notExists(). */ - public function notExists($property) { - $this->condition->notExists($property); + public function notExists($property, $langcode = NULL) { + $this->condition->notExists($property, $langcode); return $this; } diff --git a/core/lib/Drupal/Core/Entity/Query/QueryFactory.php b/core/lib/Drupal/Core/Entity/Query/QueryFactory.php index d8f3dbc..a027cbf 100644 --- a/core/lib/Drupal/Core/Entity/Query/QueryFactory.php +++ b/core/lib/Drupal/Core/Entity/Query/QueryFactory.php @@ -10,7 +10,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** - * + * Factory class Creating entity query objects. */ class QueryFactory { diff --git a/core/lib/Drupal/Core/Entity/Query/QueryInterface.php b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php index 7b12fc2..6a89265 100644 --- a/core/lib/Drupal/Core/Entity/Query/QueryInterface.php +++ b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php @@ -23,19 +23,29 @@ public function getEntityType(); /** - * @param $property - * - For conditions on the entity tables: the name of the property. - * - For conditions on fields: the name of the field, a dot and the field - * column. + * Add a condition to the query or a condition group. + * + * @param $field + * Name of the field being queried. * Some examples: * - nid * - tags.value - * - tags.langcode + * - tags this is the same as tags.value as .value is the default. + * + * 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) + * ->condition('greetings', 'merhaba', '=', 'tr'); + * ->condition('greetings.value', 'siema', '=', 'pl'); + * ->execute(); + * $entity_ids = $query->execute(); + * @endcode * - * When querying deleted fields, instead of the field name, pass in the - * field id prefixed with id: as the field name. This is normally not - * necessary. * @param $value + * The value for $field. In most cases, this is a scalar. For more complex + * options, it is an array. The meaning of each element in the array is + * dependent on $operator. * @param $operator * Possible values: * - '=', '<>', '>', '>=', '<', '<=', 'STARTS_WITH', 'CONTAINS', @@ -45,32 +55,36 @@ public function getEntityType(); * literals of the same type as the column. * - 'BETWEEN': This operator expects $value to be an array of two literals * of the same type as the column. + * @param $langcode + * Language code. Optional. * * @return \Drupal\Core\Entity\Query\QueryInterface * @see Drupal\Core\Entity\Query\andConditionGroup * @see Drupal\Core\Entity\Query\orConditionGroup */ - public function condition($property, $value = NULL, $operator = NULL); + public function condition($field, $value = NULL, $operator = NULL, $langcode = NULL); /** * Queries for the existence of a property. * - * @param $property - * Name of an entity property or a field + column. See condition() for - * more. + * @param $field + * Name of a field. + * @param $langcode + * Language code. Optional. * @return \Drupal\Core\Entity\Query\QueryInterface */ - public function exists($property); + public function exists($field, $langcode = NULL); /** * Queries for the nonexistence of a property. * - * @param $property - * Name of an entity property or a field + column. See condition() for - * more. + * @param $field. + * Name of a field. + * @param $langcode + * Language code. Optional. * @return \Drupal\Core\Entity\Query\QueryInterface */ - public function notExists($property); + public function notExists($field, $langcode = NULL); /** * Enables a pager for the query. @@ -179,7 +193,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 = drupal_container()->get('entity.query')->get('drawing'); + * $query = entity_query('drawing'); * $group = $query->andConditionGroup() * ->condition('figures.color', 'red') * ->condition('figures.shape', 'triangle'); @@ -191,20 +205,6 @@ public function conditionGroupFactory($conjunction = 'AND'); * $entity_ids = $query->execute(); * @endcode * - * To find all entities containing both the Turkish 'merhaba' and the Polish - * 'siema' within a 'greetings' text field: - * @code - * $group = $query->andConditionGroup() - * ->condition('greetings.langcode', 'tr') - * ->condition('greetings.value', 'merhaba'); - * $query->condition($group); - * $group = $query->andConditionGroup() - * ->condition('greetings.langcode', 'pl') - * ->condition('greetings.value', 'siema'); - * $query->condition($group); - * $entity_ids = $query->execute(); - * @endcode - * * @return \Drupal\Core\Entity\Query\ConditionInterface */ public function andConditionGroup(); @@ -216,7 +216,7 @@ public function andConditionGroup(); * containing 'building_type' and 'color' columns. To find all green and * red bikesheds: * @code - * $query = drupal_container()->get('entity.query')->get('map'); + * $query = entity_query('map'); * $group = $query->orConditionGroup() * ->condition('attributes.color', 'red') * ->condition('attributes.color', 'green'); diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 5daa715..ac1feaa 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -1052,7 +1052,7 @@ function field_has_data($field) { $query = $factory->get($entity_type); $group = $query->orConditionGroup(); foreach ($columns as $column) { - $group->exists($field['field_name'] .'.' . $column); + $group->exists($field['field_name'] . '.' . $column); } $result = $query ->condition($group) @@ -1302,7 +1302,7 @@ function theme_field($variables) { * An object with the properties entity_type (required), entity_id (required), * revision_id (optional) and bundle (optional). * - * @return + * @return \Drupal\Core\Entity\EntityInterface * An entity, initialized with the provided IDs. */ function _field_create_entity_from_ids($ids) { @@ -1324,5 +1324,5 @@ function _field_create_entity_from_ids($ids) { * @return array */ function field_reserved_columns() { - return array('deleted', 'langcode'); + return array('deleted'); } diff --git a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php index 1154079..cc47e59 100644 --- a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php @@ -157,9 +157,10 @@ function testDeleteFieldInstance() { $bundle = reset($this->bundles); $field = reset($this->fields); $field_name = $field['field_name']; + $factory = drupal_container()->get('entity.query'); // There are 10 entities of this bundle. - $found = drupal_container()->get('entity.query')->get('test_entity') + $found = $factory->get('test_entity') ->condition('fttype', $bundle) ->execute(); $this->assertEqual(count($found), 10, 'Correct number of entities found before deleting'); @@ -174,7 +175,7 @@ function testDeleteFieldInstance() { $this->assertEqual($instances[0]['bundle'], $bundle, 'The deleted instance is for the correct bundle'); // There are 0 entities of this bundle with non-deleted data. - $found = drupal_container()->get('entity.query')->get('test_entity') + $found = $factory->get('test_entity') ->condition('fttype', $bundle) ->condition("$field_name.deleted", 0) ->execute(); @@ -182,7 +183,7 @@ function testDeleteFieldInstance() { // There are 10 entities of this bundle when deleted fields are allowed, and // their values are correct. - $found = drupal_container()->get('entity.query')->get('test_entity') + $found = $factory->get('test_entity') ->condition('fttype', $bundle) ->condition("$field_name.deleted", 1) ->sort('ftid') @@ -191,7 +192,7 @@ function testDeleteFieldInstance() { 'entity_type' => 'test_entity', 'bundle' => $bundle, ); - $entities = array();; + $entities = array(); foreach ($found as $entity_id) { $ids->entity_id = $entity_id; $entities[$entity_id] = _field_create_entity_from_ids($ids); @@ -228,7 +229,7 @@ function testPurgeInstance() { field_purge_batch($batch_size); // There are $count deleted entities left. - $found = drupal_container()->get('entity.query')->get('test_entity') + $found = entity_query('test_entity') ->condition('fttype', $bundle) ->condition($field['field_name'] . '.deleted', 1) ->execute(); diff --git a/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Condition.php b/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Condition.php index 6cfad95..8e4b73d 100644 --- a/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Condition.php +++ b/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Condition.php @@ -19,10 +19,10 @@ class Condition extends ConditionBase { */ public function compile($conditionContainer) { // If this is not the top level condition group then the sql query is - // added to the $conditionContainer object by this function itself. The SQL query - // object is only necessary to pass to Query::addField() so that it can - // join tables as necessary. conditions need to be added to the $conditionContainer - // object to keep grouping. + // added to the $conditionContainer object by this function itself. The + // SQL query object is only necessary to pass to Query::addField() so it + // can join tables as necessary. On the other hand, conditions need to be + // added to the $conditionContainer object to keep grouping. $sqlQuery = $conditionContainer instanceof SelectInterface ? $conditionContainer : $conditionContainer->sqlQuery; $tables = new Tables($sqlQuery); foreach ($this->conditions as $condition) { @@ -35,9 +35,21 @@ public function compile($conditionContainer) { } else { $type = strtoupper($this->conjunction) == 'OR' || $condition['operator'] == 'IS NULL' ? 'LEFT' : 'INNER'; - $field = $tables->addField($condition['field'], $type); $this->translateCondition($condition); - $conditionContainer->condition($field, $condition['value'], $condition['operator']); + $field = $tables->addField($condition['field'], $type, $table); + if ($condition['langcode']) { + // Even inside an OR condition group the language code and the + // actual condition need to be ANDed together. For AND conditions + // this is not necessary but it simplifies the code. + $and = new SqlCondition('AND'); + $and + ->condition("$table.langcode", $condition['langcode']) + ->condition($field, $condition['value'], $condition['operator']); + $conditionContainer->condition($and); + } + else { + $conditionContainer->condition($field, $condition['value'], $condition['operator']); + } } } } @@ -45,15 +57,15 @@ public function compile($conditionContainer) { /** * Implements Drupal\Core\Entity\Query\ConditionInterface::exists(). */ - public function exists($field) { - return $this->condition($field, NULL, 'IS NOT NULL'); + public function exists($field, $langcode = NULL) { + return $this->condition($field, NULL, 'IS NOT NULL', $langcode); } /** * Implements Drupal\Core\Entity\Query\ConditionInterface::notExists(). */ - public function notExists($field) { - return $this->condition($field, NULL, 'IS NULL'); + public function notExists($field, $langcode = NULL) { + return $this->condition($field, NULL, 'IS NULL', $langcode); } protected function translateCondition(&$condition) { @@ -62,14 +74,17 @@ protected function translateCondition(&$condition) { $condition['value'] .= '%'; $condition['operator'] = 'LIKE'; break; + case 'CONTAINS': $condition['value'] = '%' . $condition['value'] . '%'; $condition['operator'] = 'LIKE'; break; + case 'ENDS_WITH': $condition['value'] = '%' . $condition['value']; $condition['operator'] = 'LIKE'; break; + } } diff --git a/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Query.php b/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Query.php index 7021b27..c96720a 100644 --- a/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Query.php +++ b/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Query.php @@ -10,6 +10,9 @@ use Drupal\Core\Entity\Query\QueryBase; use Drupal\Core\Entity\Query\QueryException; +/** + * The SQL storage entity query class. + */ class Query extends QueryBase { /** @@ -46,6 +49,12 @@ public function execute() { if (!isset($entity_info['base table'])) { throw new QueryException("No base table, nothing to query."); } + $configurable_fields = array(); + foreach (field_info_instances($this->entityType) as $instances) { + foreach ($instances as $field_name => $instance) { + $configurable_fields[$field_name] = TRUE; + } + } $base_table = $entity_info['base table']; // Assemble a list of entity tables, primarily for use in // \Drupal\field_sql_storage\Entity\Tables::ensureEntityTable(). @@ -61,6 +70,7 @@ public function execute() { } $entity_tables[$base_table] = drupal_get_schema($base_table); $sqlQuery = $this->connection->select($base_table, 'base_table', array('conjunction' => $this->conjunction)); + $sqlQuery->addMetaData('configurable_fields', $configurable_fields); // Determines the key of the column to join on. This is either the entity // id key or the revision id key, depending on whether the entity type // supports revisions. diff --git a/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/QueryFactory.php b/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/QueryFactory.php index 25e0705..22739df 100644 --- a/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/QueryFactory.php +++ b/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/QueryFactory.php @@ -2,13 +2,16 @@ /** * @file - * Definition of Drupal\field_sql_storage\EntityQueryFactory. + * Definition of Drupal\field_sql_storage\Entity\QueryFactory. */ namespace Drupal\field_sql_storage\Entity; use Drupal\Core\Database\Connection; +/** + * Factory class creating entity query objects for the SQL backend. + */ class QueryFactory { function __construct(Connection $connection) { diff --git a/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Tables.php b/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Tables.php index d9483ac..1c1b8c5 100644 --- a/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Tables.php +++ b/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Tables.php @@ -1,5 +1,8 @@ ensureEntityTable($property, $type); + function addField($field, $type, &$table = NULL) { + $parts = explode('.', $field); + $property = $parts[0]; + $configurable_fields = $this->sqlQuery->getMetaData('configurable_fields'); + if (!empty($configurable_fields[$property]) || substr($property, 0, 3) == 'id:') { + $field_name = $property; + $table = $this->ensureFieldTable($field_name, $type); + // Default to .value. + $column = isset($parts[1]) ? $parts[1] : 'value'; + $sql_column = _field_sql_storage_columnname($field_name, $column); } else { - list($field_name, $column) = $parts; - $sql_column = _field_sql_storage_columnname($field_name, $column); - $table = $this->ensureFieldTable($field_name, $type); + $sql_column = $property; + $table = $this->ensureEntityTable($property, $type); } return "$table.$sql_column"; } @@ -99,7 +108,7 @@ protected function ensureEntityTable($property, $type = 'INNER') { * @return string * @throws \Drupal\Core\Entity\Query\QueryException */ - protected function ensureFieldTable($field_name, $type = 'INNER') { + protected function ensureFieldTable(&$field_name, $type = 'INNER') { if (!isset($this->fieldTables[$field_name])) { // This is field_purge_batch() passing in a field id. if (substr($field_name, 0, 3) == 'id:') { @@ -111,6 +120,9 @@ protected function ensureFieldTable($field_name, $type = 'INNER') { if (!$field) { throw new QueryException(format_string('field @field_name not found', array('@field_name' => $field_name))); } + // This is really necessary only for the id: case but it can't be run + // before throwing the exception. + $field_name = $field['field_name']; $table = $this->sqlQuery->getMetaData('age') == FIELD_LOAD_CURRENT ? _field_sql_storage_tablename($field) : _field_sql_storage_revision_tablename($field); $field_id_field = $this->sqlQuery->getMetaData('field_id_field'); $entity_id_field = $this->sqlQuery->getMetaData('entity_id_field'); diff --git a/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/FieldSqlStorageBundle.php b/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/FieldSqlStorageBundle.php index 23c75e1..2d5f996 100644 --- a/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/FieldSqlStorageBundle.php +++ b/core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/FieldSqlStorageBundle.php @@ -1,5 +1,10 @@ get('entity.query'); foreach ($field['bundles'] as $entity_type => $bundle) { $result = $factory->get($entity_type) - ->condition($field['field_name'] .'.value', $values) + ->condition($field['field_name'] . '.value', $values) ->count() ->skipAccessCheck() ->range(0, 1) diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index 0116155..4688926 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -939,7 +939,6 @@ function file_field_formatter_view($entity_type, $entity, $field, $instance, $la * The field column if the field references {file_managed}.fid, typically * fid, FALSE if it doesn't. */ - function file_field_find_file_reference_column($field) { foreach ($field['foreign keys'] as $data) { if ($data['table'] == 'file_managed') { diff --git a/core/modules/node/tests/modules/node_access_test/node_access_test.module b/core/modules/node/tests/modules/node_access_test/node_access_test.module index 2b6ed07..f5fc00f 100644 --- a/core/modules/node/tests/modules/node_access_test/node_access_test.module +++ b/core/modules/node/tests/modules/node_access_test/node_access_test.module @@ -150,7 +150,7 @@ function node_access_test_page() { function node_access_entity_test_page() { $output = ''; try { - $result = drupal_container()->get('entity.query')->get('node') + $result = entity_query('node') ->condition('body.value', 'A', 'STARTS_WITH') ->execute(); if (!empty($result)) { diff --git a/core/modules/system/lib/Drupal/system/Tests/Database/UpdateComplexTest.php b/core/modules/system/lib/Drupal/system/Tests/Database/UpdateComplexTest.php index e0bfb56..4778363 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Database/UpdateComplexTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Database/UpdateComplexTest.php @@ -23,7 +23,7 @@ public static function getInfo() { /** * Tests updates with OR conditionals. */ - function testorConditionGroupUpdate() { + function testOrConditionUpdate() { $update = db_update('test') ->fields(array('job' => 'Musician')) ->condition(db_or() diff --git a/core/modules/system/lib/Drupal/system/Tests/Database/UpdateTest.php b/core/modules/system/lib/Drupal/system/Tests/Database/UpdateTest.php index 8bcdad4..c5acd78 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Database/UpdateTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Database/UpdateTest.php @@ -94,7 +94,7 @@ function testWhereUpdate() { /** * Confirms that we can stack condition and where calls. */ - function testWhereandConditionGroupUpdate() { + function testWhereAndConditionUpdate() { $update = db_update('test') ->fields(array('job' => 'Musician')) ->where('age > :age', array(':age' => 26)) diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php index a93a794..c6510fc 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php @@ -88,6 +88,8 @@ function setUp() { } $bundles[] = $bundle; } + $GLOBALS['debug'] = TRUE; + unset($GLOBALS['debug']); // Each unit is a list of field name, langcode and a column-value array. $units[] = array($figures, LANGUAGE_NOT_SPECIFIED, array( 'color' => 'red', @@ -97,8 +99,16 @@ function setUp() { 'color' => 'blue', 'shape' => 'circle', )); - $units[] = array($greetings, 'tr', array('value' => 'merhaba')); - $units[] = array($greetings, 'pl', array('value' => 'siema')); + // To make it easier to test sorting, the greetings get formats according + // to their langcode. + $units[] = array($greetings, 'tr', array( + 'value' => 'merhaba', + 'format' => 'format-tr' + )); + $units[] = array($greetings, 'pl', array( + 'value' => 'siema', + 'format' => 'format-pl' + )); // Make these languages available to the greetings field. $field_langcodes = &drupal_static('field_available_languages'); $field_langcodes['test_entity'][$greetings] = array('tr', 'pl'); @@ -149,7 +159,7 @@ function testEntityQuery() { $greetings = $this->greetings; $figures = $this->figures; $this->queryResults = $this->factory->get('test_entity') - ->condition("$greetings.langcode", 'tr') + ->exists($greetings, 'tr') ->condition("$figures.color", 'red') ->sort('ftid') ->execute(); @@ -158,7 +168,7 @@ function testEntityQuery() { $this->assertResult(5, 7, 13, 15); $this->queryResults = $this->factory->get('test_entity', 'OR') - ->condition("$greetings.langcode", 'tr') + ->exists($greetings, 'tr') ->condition("$figures.color", 'red') ->sort('ftid') ->execute(); @@ -168,7 +178,7 @@ function testEntityQuery() { $query = $this->factory->get('test_entity'); $group = $query->orConditionGroup() - ->condition("$greetings.langcode", 'tr') + ->exists($greetings, 'tr') ->condition("$figures.color", 'red'); $this->queryResults = $query ->condition($group) @@ -218,7 +228,7 @@ function testEntityQuery() { $entity->{$greetings}['tr'][0]['value'] = 'xsiemax'; $entity->save(); } - // When querying current revisions, this string + // When querying current revisions, this string is no longer found. $this->queryResults = $this->factory->get('test_entity') ->condition("$greetings.value", 'merhaba') ->execute(); @@ -281,7 +291,7 @@ function testSort() { $this->assertResult(range(15, 1)); $query = $this->factory->get('test_entity') ->sort("$figures.color") - ->sort("$greetings.langcode") + ->sort("$greetings.format") ->sort('ftid'); // As we do not have any conditions, here are the possible colors and // language codes, already in order, with the first occurence of the @@ -327,7 +337,7 @@ function testSort() { $_GET['page'] = '0,2'; $this->queryResults = $this->factory->get('test_entity') ->sort("$figures.color") - ->sort("$greetings.langcode") + ->sort("$greetings.format") ->sort('ftid') ->pager(4, 1) ->execute(); @@ -336,7 +346,7 @@ function testSort() { // Now test the reversed order. $query = $this->factory->get('test_entity') ->sort("$figures.color", 'DESC') - ->sort("$greetings.langcode", 'DESC') + ->sort("$greetings.format", 'DESC') ->sort('ftid', 'DESC'); $count_query = clone $query; $this->assertEqual(15, $count_query->count()->execute()); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php index 5d8970c..733c80f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php @@ -269,18 +269,13 @@ function testMultilingualProperties() { // Test property conditions and orders with multiple languages in the same // query. - $query = drupal_container()->get('entity.query')->get('entity_test'); - $default_langcode_group = $query->andConditionGroup() - ->condition('langcode', $default_langcode) - ->condition('user_id', $properties[$default_langcode]['user_id']) - ->condition('name', $properties[$default_langcode]['name']); - $langcode_group = $query->andConditionGroup() - ->condition('langcode', $langcode) - ->condition('name', $properties[$langcode]['name']); + $query = entity_query('entity_test'); + $group = $query->andConditionGroup() + ->condition('user_id', $properties[$default_langcode]['user_id'], '=', $default_langcode) + ->condition('name', $properties[$default_langcode]['name'], '=', $default_langcode); $result = $query - ->condition('langcode', $default_langcode) - ->condition($default_langcode_group) - ->condition($langcode_group) + ->condition($group) + ->condition('name', $properties[$langcode]['name'], '=', $langcode) ->execute(); $this->assertEqual(count($result), 1, 'One entity loaded by name and uid using different language meta conditions.'); @@ -289,16 +284,13 @@ function testMultilingualProperties() { $field_value = $this->randomString(); $entity->getTranslation($langcode)->set($this->field_name, array(array('value' => $field_value))); $entity->save(); - $query = drupal_container()->get('entity.query')->get('entity_test'); + $query = entity_query('entity_test'); $default_langcode_group = $query->andConditionGroup() - ->condition('langcode', $default_langcode) - ->condition('user_id', $properties[$default_langcode]['user_id']) - ->condition('name', $properties[$default_langcode]['name']); + ->condition('user_id', $properties[$default_langcode]['user_id'], '=', $default_langcode) + ->condition('name', $properties[$default_langcode]['name'], '=', $default_langcode); $langcode_group = $query->andConditionGroup() - ->condition('langcode', $langcode) - ->condition('name', $properties[$langcode]['name']) - ->condition("$this->field_name.value", $field_value) - ->condition("$this->field_name.langcode", $langcode); + ->condition('name', $properties[$langcode]['name'], '=', $langcode) + ->condition("$this->field_name.value", $field_value, '=', $langcode); $result = $query ->condition('langcode', $default_langcode) ->condition($default_langcode_group) diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php index 61d4f4b..d8a3ca5 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php @@ -37,7 +37,7 @@ function testTaxonomyEfq() { $term = $this->createTerm($this->vocabulary); $terms[$term->tid] = $term; } - $result = drupal_container()->get('entity.query')->get('taxonomy_term')->execute(); + $result = entity_query('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 = drupal_container()->get('entity.query')->get('taxonomy_term') + $result = entity_query('taxonomy_term') ->condition('vid', $vocabulary2->vid) ->execute(); sort($result);