summaryrefslogtreecommitdiff
path: root/modules/taxonomy/taxonomy.module
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2012-06-03 18:56:13 -0400
committerDavid Rothstein <drothstein@gmail.com>2012-06-03 18:56:13 -0400
commitf209013a5181f6b4e6c435fcc796ee9825aedbc6 (patch)
treeceae24420a85658586271774b5a401ad3b54ad79 /modules/taxonomy/taxonomy.module
parentd98d58655d513c737f60486ecc4a92f82aece868 (diff)
downloadbrdo-f209013a5181f6b4e6c435fcc796ee9825aedbc6.tar.gz
brdo-f209013a5181f6b4e6c435fcc796ee9825aedbc6.tar.bz2
Issue #1054162 by tim.plunkett, Dave Reid, joachim, no_commit_credit, Berdir: Taxonomy bundles not supported by EntityFieldQuery.
Diffstat (limited to 'modules/taxonomy/taxonomy.module')
-rw-r--r--modules/taxonomy/taxonomy.module32
1 files changed, 32 insertions, 0 deletions
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index ca77907ae..ee12be718 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -1906,3 +1906,35 @@ function taxonomy_taxonomy_term_delete($term) {
/**
* @} End of "defgroup taxonomy_index".
*/
+
+/**
+ * Implements hook_entity_query_alter().
+ *
+ * Converts EntityFieldQuery instances on taxonomy terms that have an entity
+ * condition on term bundles (vocabulary machine names). Since the vocabulary
+ * machine name is not present in the {taxonomy_term_data} table itself, we have
+ * to convert the bundle condition into a proprety condition of vocabulary IDs
+ * to match against {taxonomy_term_data}.vid.
+ */
+function taxonomy_entity_query_alter($query) {
+ $conditions = &$query->entityConditions;
+
+ // Alter only taxonomy term queries with bundle conditions.
+ if (isset($conditions['entity_type']) && $conditions['entity_type']['value'] == 'taxonomy_term' && isset($conditions['bundle'])) {
+ // Convert vocabulary machine names to vocabulary IDs.
+ $vocabulary_data = taxonomy_vocabulary_get_names();
+ $vids = array();
+ if (is_array($conditions['bundle']['value'])) {
+ foreach ($conditions['bundle']['value'] as $vocabulary_machine_name) {
+ $vids[] = $vocabulary_data[$vocabulary_machine_name]->vid;
+ }
+ }
+ else {
+ $vocabulary_machine_name = $conditions['bundle']['value'];
+ $vids = $vocabulary_data[$vocabulary_machine_name]->vid;
+ }
+
+ $query->propertyCondition('vid', $vids, $conditions['bundle']['operator']);
+ unset($conditions['bundle']);
+ }
+}