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 b8d9f3a..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 @@ -107,6 +107,13 @@ public function execute() { $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 @@ 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.'); + } }