You are here

function hs_taxonomy_hierarchical_select_root_level in Hierarchical Select 6.3

Same name and namespace in other branches
  1. 5.3 modules/hs_taxonomy.module \hs_taxonomy_hierarchical_select_root_level()
  2. 7.3 modules/hs_taxonomy.module \hs_taxonomy_hierarchical_select_root_level()

Implementation of hook_hierarchical_select_root_level().

1 call to hs_taxonomy_hierarchical_select_root_level()
hs_taxonomy_views_hierarchical_select_root_level in modules/hs_taxonomy_views.module
Implementation of hook_hierarchical_select_root_level().

File

modules/hs_taxonomy.module, line 380
Implementation of the Hierarchical Select API for the Taxonomy module.

Code

function hs_taxonomy_hierarchical_select_root_level($params) {
  $terms = _hs_taxonomy_hierarchical_select_get_tree($params['vid'], 0, -1, 1);

  // If the root_term parameter is enabled, then prepend a fake "<root>" term.
  if (isset($params['root_term']) && $params['root_term'] === TRUE) {
    $root_term = new StdClass();
    $root_term->tid = 0;
    $root_term->name = '<' . t('root') . '>';
    $terms = array_merge(array(
      $root_term,
    ), $terms);
  }

  // Unset the term that's being excluded, if it is among the terms.
  if (isset($params['exclude_tid'])) {
    foreach ($terms as $key => $term) {
      if ($term->tid == $params['exclude_tid']) {
        unset($terms[$key]);
      }
    }
  }

  // If the Term Permissions module is installed, honor its settings.
  if (function_exists('term_permissions_allowed')) {
    global $user;
    foreach ($terms as $key => $term) {
      if (!term_permissions_allowed($term->tid, $user)) {
        unset($terms[$key]);
      }
    }
  }
  return _hs_taxonomy_hierarchical_select_terms_to_options($terms);
}