Returns the set of valid terms for a taxonomy field.
$field: The field definition.
$instance: The instance definition. It is recommended to only use instance level properties to filter out values from a list defined by field level properties.
$entity_type: The entity type the field is attached to.
$entity: The entity object the field is attached to, or NULL if no entity exists (e.g. in field settings page).
The array of valid terms for this field, keyed by term id.
function taxonomy_allowed_values($field, $instance, $entity_type, $entity) {
$options = array();
foreach ($field['settings']['allowed_values'] as $tree) {
if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) {
if ($terms = taxonomy_get_tree($vocabulary->vid, $tree['parent'], NULL, TRUE)) {
foreach ($terms as $term) {
$options[$term->tid] = str_repeat('-', $term->depth) . $term
->label();
}
}
}
}
return $options;
}