You are here

function _global_filter_add_terms in Views Global Filter 8

Same name and namespace in other branches
  1. 6 global_filter.module \_global_filter_add_terms()
  2. 7 global_filter.widgets.inc \_global_filter_add_terms()

Add terms to global filter.

2 calls to _global_filter_add_terms()
global_filter_create_widget in ./global_filter.widgets.inc
Based on the requested or field-implied widget.
_global_filter_configure_form in ./global_filter.blocks.inc
Generates the filter configuration form for filters in a block.

File

./global_filter.widgets.inc, line 559
global_filter.widgets.inc

Code

function _global_filter_add_terms(&$options, $vocabulary_machine_name, $show_depth = TRUE) {
  if (!module_exists('taxonomy')) {
    drupal_set_message(t('Global Filter: using vocabulary %vocabulary, but Taxonomy module is not enabled.', array(
      '%vocabulary' => $vocabulary_machine_name,
    )), 'error');
    return;
  }
  if (!empty($vocabulary_machine_name)) {
    foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
      $found = $vocabulary->machine_name == $vocabulary_machine_name;
      if ($found) {
        break;
      }
    }
  }
  if (empty($found)) {
    drupal_set_message(t('Global Filter: the vocabulary %vocabulary does not exist.', array(
      '%vocabulary' => $vocabulary_machine_name,
    )), 'error');
  }
  else {
    foreach (taxonomy_get_tree($vid) as $term) {

      // If $show_depth is set, we follow core's way and add one hyphen for each
      // hierarchy level.
      $options[$term->tid] = $show_depth ? str_repeat('-', $term->depth) . $term->name : $term->name;
    }
  }
}