summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2012-11-07 01:16:21 -0800
committerwebchick2012-11-07 01:16:21 -0800
commit07030912aa9189f2b4b9e3a7f49fe7be1211ee98 (patch)
treeb1ccecc7a10125983fe86f8937a9c312c918c027
parentb6af60e11d6558476adf3531d1477397536d0f96 (diff)
Issue #1828408 by Amitaibu: Fixed Re-add addTag() and AddMetaData() to EFQ.
-rw-r--r--core/lib/Drupal/Core/Entity/Query/QueryBase.php44
-rw-r--r--core/lib/Drupal/Core/Entity/Query/QueryInterface.php4
-rw-r--r--core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Query.php14
-rw-r--r--core/modules/field/tests/modules/field_test/field_test.module11
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php16
5 files changed, 88 insertions, 1 deletions
diff --git a/core/lib/Drupal/Core/Entity/Query/QueryBase.php b/core/lib/Drupal/Core/Entity/Query/QueryBase.php
index 9ad26e1..d22dbac 100644
--- a/core/lib/Drupal/Core/Entity/Query/QueryBase.php
+++ b/core/lib/Drupal/Core/Entity/Query/QueryBase.php
@@ -239,4 +239,48 @@ abstract class QueryBase implements QueryInterface {
function __clone() {
$this->condition = clone $this->condition;
}
+
+ /**
+ * Implements Drupal\Core\Database\Query\AlterableInterface::addTag().
+ */
+ public function addTag($tag) {
+ $this->alterTags[$tag] = 1;
+ return $this;
+ }
+
+ /**
+ * Implements Drupal\Core\Database\Query\AlterableInterface::hasTag().
+ */
+ public function hasTag($tag) {
+ return isset($this->alterTags[$tag]);
+ }
+
+ /**
+ * Implements Drupal\Core\Database\Query\AlterableInterface::hasAllTags().
+ */
+ public function hasAllTags() {
+ return !(boolean)array_diff(func_get_args(), array_keys($this->alterTags));
+ }
+
+ /**
+ * Implements Drupal\Core\Database\Query\AlterableInterface::hasAnyTag().
+ */
+ public function hasAnyTag() {
+ return (boolean)array_intersect(func_get_args(), array_keys($this->alterTags));
+ }
+
+ /**
+ * Implements Drupal\Core\Database\Query\AlterableInterface::addMetaData().
+ */
+ public function addMetaData($key, $object) {
+ $this->alterMetaData[$key] = $object;
+ return $this;
+ }
+
+ /**
+ * Implements Drupal\Core\Database\Query\AlterableInterface::getMetaData().
+ */
+ public function getMetaData($key) {
+ return isset($this->alterMetaData[$key]) ? $this->alterMetaData[$key] : NULL;
+ }
}
diff --git a/core/lib/Drupal/Core/Entity/Query/QueryInterface.php b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php
index 477de7d..ec9627e 100644
--- a/core/lib/Drupal/Core/Entity/Query/QueryInterface.php
+++ b/core/lib/Drupal/Core/Entity/Query/QueryInterface.php
@@ -7,13 +7,15 @@
namespace Drupal\Core\Entity\Query;
+use Drupal\Core\Database\Query\AlterableInterface;
+
/**
* Interface for entity queries.
*
* Never instantiate classes implementing this interface directly. Always use
* the QueryFactory class.
*/
-interface QueryInterface {
+interface QueryInterface extends AlterableInterface {
/**
* Gets the entity type for this query.
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 44023ce..4a0b440 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
@@ -100,6 +100,20 @@ class Query extends QueryBase {
}
$sqlQuery->addTag('entity_query');
$sqlQuery->addTag('entity_query_' . $this->entityType);
+
+ // Add further tags added.
+ if (isset($this->alterTags)) {
+ foreach ($this->alterTags as $tag => $value) {
+ $sqlQuery->addTag($tag);
+ }
+ }
+
+ // Add further metadata added.
+ if (isset($this->alterMetaData)) {
+ foreach ($this->alterMetaData as $key => $value) {
+ $sqlQuery->addMetaData($key, $value);
+ }
+ }
// This now contains first the table containing entity properties and
// last the entity base table. They might be the same.
$sqlQuery->addMetaData('entity_tables', $entity_tables);
diff --git a/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module
index a50dc5d..26ef868 100644
--- a/core/modules/field/tests/modules/field_test/field_test.module
+++ b/core/modules/field/tests/modules/field_test/field_test.module
@@ -262,6 +262,17 @@ function field_test_query_efq_table_prefixing_test_alter(&$query) {
$query->join('test_entity','te2','%alias.ftid = test_entity.ftid');
}
+
+/**
+ * Implements hook_query_TAG_alter() for tag 'efq_metadata_test'.
+ *
+ * @see Drupal\system\Tests\Entity\EntityQueryTest::testMetaData()
+ */
+function field_test_query_efq_metadata_test_alter(&$query) {
+ global $efq_test_metadata;
+ $efq_test_metadata = $query->getMetadata('foo');
+}
+
/**
* Implements hook_field_formatter_settings_form_alter().
*/
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 8c04faa..1882e6f 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php
@@ -453,4 +453,20 @@ class EntityQueryTest extends WebTestBase {
$this->assertTrue($ok, format_string("$i is after all entities in bundle2"));
}
}
+
+ /**
+ * Test adding a tag and metadata to the Entity query object.
+ *
+ * The tags and metadata should propogate to the SQL query object.
+ */
+ function testMetaData() {
+ $query = entity_query('test_entity');
+ $query
+ ->addTag('efq_metadata_test')
+ ->addMetaData('foo', 'bar')
+ ->execute();
+
+ global $efq_test_metadata;
+ $this->assertEqual($efq_test_metadata, 'bar', 'Tag and metadata propogated to the SQL query object.');
+ }
}