You are here

function _taxonomy_access_get_descendants in Taxonomy Access Control 7

Same name and namespace in other branches
  1. 6 taxonomy_access.module \_taxonomy_access_get_descendants()

Gets term IDs for all descendants of the given term.

Parameters

int $tid: The term ID for which to fetch children.

Return value

array An array of the IDs of the term's descendants.

Related topics

1 call to _taxonomy_access_get_descendants()
taxonomy_access_add_term_submit in ./taxonomy_access.admin.inc
Form submission handler for taxonomy_access_admin_role().

File

./taxonomy_access.module, line 851
Allows administrators to specify access control for taxonomy categories.

Code

function _taxonomy_access_get_descendants($tid) {
  $descendants =& drupal_static(__FUNCTION__, array());
  if (!isset($descendants[$tid])) {

    // Preserve the original state of the list flag.
    $flag_state = taxonomy_access_list_enabled();

    // Enforce that list grants do not filter the results.
    taxonomy_access_disable_list();
    $descendants[$tid] = array();
    $term = taxonomy_term_load($tid);
    $tree = taxonomy_get_tree($term->vid, $tid);
    foreach ($tree as $term) {
      $descendants[$tid][] = $term->tid;
    }

    // Restore list flag to previous state.
    if ($flag_state) {
      taxonomy_access_enable_list();
    }
    unset($term);
    unset($tree);
  }
  return $descendants[$tid];
}