You are here

function workbench_access_query_term_access_alter in Workbench Access 7

Implements hook_query_TAG_alter().

If this is a restricted taxonomy autocomplete query, add the conditions required by Workbench Access.

See also

taxonomy_autocomplete()

File

modules/taxonomy.workbench_access.inc, line 319
Taxonomy integration for Workbench Access.

Code

function workbench_access_query_term_access_alter(QueryAlterableInterface $query) {
  global $user;
  if (workbench_access_is_active_autocomplete()) {

    // Iterate through the query tables to find the taxonomy_term_data table alias
    $term_data_alias = 't';
    $tables = $query
      ->getTables();
    foreach ($tables as $table_alias => $table_info) {
      if ($table_info['table'] == 'taxonomy_term_data') {
        $term_data_alias = $table_alias;
        break;
      }
    }

    // Alter the query.
    if (!isset($user->workbench_access)) {
      workbench_access_user_load_data($user);
    }
    $tree = workbench_access_get_user_tree($user);
    if (!empty($tree)) {
      $query
        ->condition($term_data_alias . '.tid', array_keys($tree), 'IN');
    }
    else {
      $query
        ->condition($term_data_alias . '.tid', -10);
    }
  }
}