You are here

function xmlsitemap_taxonomy_entity_query_alter in XML sitemap 7.2

Implements hook_entity_query_alter().

@todo Remove when https://www.drupal.org/node/1054162 is fixed.

File

xmlsitemap_taxonomy/xmlsitemap_taxonomy.module, line 251
Main file for XML sitemap taxonomy.

Code

function xmlsitemap_taxonomy_entity_query_alter($query) {
  $conditions =& $query->entityConditions;

  // Alter taxonomy term queries only.
  if (isset($conditions['entity_type']) && $conditions['entity_type']['value'] == 'taxonomy_term' && isset($conditions['bundle'])) {

    // We can only support the operators that are explicit in values.
    if (in_array($conditions['bundle']['operator'], array(
      NULL,
      '=',
      '!=',
      'IN',
      'NOT IN',
    ))) {
      $vids = array();

      // Convert vocabulary machine names to vocabulary IDs.
      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']);
    }
  }
}