function services_entity_entity_query_alter in Services Entity API 7.2
Same name and namespace in other branches
- 7 services_entity.module \services_entity_entity_query_alter()
Implements hook_entity_query_alter().
Convert EntityFieldQuerys 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.
@TODO Remove when http://drupal.org/node/1054162 gets fixed.
File
- ./
services_entity.module, line 118
Code
function services_entity_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.
$vids = array();
if (is_array($conditions['bundle']['value'])) {
foreach ($conditions['bundle']['value'] as $vocabulary_machine_name) {
$vocabulary = taxonomy_vocabulary_machine_name_load($vocabulary_machine_name);
$vids[] = $vocabulary->vid;
}
}
else {
$vocabulary = taxonomy_vocabulary_machine_name_load($conditions['bundle']['value']);
$vids = $vocabulary->vid;
}
$query
->propertyCondition('vid', $vids, $conditions['bundle']['operator']);
unset($conditions['bundle']);
}
}