Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
07030912
Commit
07030912
authored
Nov 07, 2012
by
webchick
Browse files
Issue
#1828408
by Amitaibu: Fixed Re-add addTag() and AddMetaData() to EFQ.
parent
b6af60e1
Changes
5
Hide whitespace changes
Inline
Side-by-side
core/lib/Drupal/Core/Entity/Query/QueryBase.php
View file @
07030912
...
...
@@ -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
;
}
}
core/lib/Drupal/Core/Entity/Query/QueryInterface.php
View file @
07030912
...
...
@@ -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.
...
...
core/modules/field/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Query.php
View file @
07030912
...
...
@@ -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
);
...
...
core/modules/field/tests/modules/field_test/field_test.module
View file @
07030912
...
...
@@ -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().
*/
...
...
core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php
View file @
07030912
...
...
@@ -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.'
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment