You are here

function content_taxonomy_options_array in Content Taxonomy 5

Helper function to create a tree of options

1 call to content_taxonomy_options_array()
content_taxonomy_options_widget in ./content_taxonomy_options.module
Implementation of hook_widget().

File

./content_taxonomy_options.module, line 176
Defines a widget type for content_taxonomy for options

Code

function content_taxonomy_options_array($vid, $parent = NULL, $depth = 0, $blank_field = TRUE, $show_depth = FALSE) {
  $options = array();
  if ($depth == 1) {
    $tree = taxonomy_get_children($parent, $vid);
  }
  else {
    $tree = taxonomy_get_tree($vid, $parent, -1, $depth);
  }
  if ($blank_field) {
    $options[0] = '---';
  }
  if ($tree) {
    foreach ($tree as $term) {
      if ($show_depth) {
        $value = str_repeat('- ', $term->depth) . $term->name;
      }
      else {
        $value = $term->name;
      }
      $options[$term->tid] = $value;
    }
  }
  return $options;
}