You are here

function content_taxonomy_allowed_values in Content Taxonomy 7

Same name and namespace in other branches
  1. 6.2 content_taxonomy.module \content_taxonomy_allowed_values()
  2. 6 content_taxonomy.module \content_taxonomy_allowed_values()

Returns the set of valid terms for a taxonomy field. Extends taxonomy_allowed_values() with the tree depth option.

Parameters

$field: The field definition.

Return value

The array of valid terms for this field, keyed by term id.

2 string references to 'content_taxonomy_allowed_values'
content_taxonomy_disable in ./content_taxonomy.install
Implements hook_disable().
content_taxonomy_field_info_alter in ./content_taxonomy.module
Implements hook_field_info_alter().

File

./content_taxonomy.module, line 76

Code

function content_taxonomy_allowed_values($field) {
  $options = array();
  foreach ($field['settings']['allowed_values'] as $tree) {
    if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) {
      $max_depth = isset($tree['depth']) && !empty($tree['depth']) ? $tree['depth'] : NULL;
      $terms = content_taxonomy_get_terms($field, $vocabulary, $tree['parent'], $max_depth);
      if (!empty($terms) && is_array($terms)) {
        foreach ($terms as $term) {
          $options[$term->tid] = str_repeat('- ', $term->depth) . $term->name;
        }
      }
    }
  }
  return $options;
}