Commit 07030912 authored by webchick's avatar webchick

Issue #1828408 by Amitaibu: Fixed Re-add addTag() and AddMetaData() to EFQ.

parent b6af60e1
......@@ -239,4 +239,48 @@ public function tableSort(&$headers) {
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;
}
}
......@@ -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.
......
......@@ -100,6 +100,20 @@ public function execute() {
}
$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);
......
......@@ -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().
*/
......
......@@ -453,4 +453,20 @@ protected function assertBundleOrder($order) {
$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.');
}
}
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