You are here

function facetapi_callback_taxonomy_values in Facet API 6

Returns values for vocabulary facets.

Parameters

$facet: An array containing the facet definition.

Return value

An array of values passed as options to the form element.

1 string reference to 'facetapi_callback_taxonomy_values'
facetapi_facetapi_facet_info in ./facetapi.module
Implementation of hook_facetapi_facet_info().

File

./facetapi.callbacks.inc, line 198
Various callbacks referenced in facet definitions.

Code

function facetapi_callback_taxonomy_values(array $facet) {

  // Extracts vid, loads vocabulary object, returns empty array on any error.
  if (!preg_match('/^vocabulary_(\\d+)$/', $facet['name'], $match)) {
    return array();
  }
  if (!($vocabulary = taxonomy_vocabulary_load($match[1]))) {
    return array();
  }

  // Builds options from taxonomy tree.
  $options = array();
  $tree = taxonomy_get_tree($vocabulary->vid);
  if ($tree && count($tree) > 0) {
    $options[$vocabulary->name] = array();
    foreach ($tree as $term) {
      $options[$vocabulary->name][$term->tid] = check_plain(str_repeat('-', $term->depth) . $term->name);
    }
  }
  return $options;
}