function taxonomy_allowed_values

Returns the set of valid terms for a taxonomy field.

Parameters

$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.

\Drupal\Core\Entity\EntityInterface $entity: The entity object the field is attached to.

Return value

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

1 string reference to 'taxonomy_allowed_values'
taxonomy_options_list in drupal/core/modules/taxonomy/taxonomy.module
Implements hook_options_list().

File

drupal/core/modules/taxonomy/taxonomy.module, line 1015
Enables the organization of content into categories.

Code

function taxonomy_allowed_values($field, $instance, EntityInterface $entity) {
  $options = array();
  foreach ($field['settings']['allowed_values'] as $tree) {
    if ($vocabulary = taxonomy_vocabulary_load($tree['vocabulary'])) {
      if ($terms = taxonomy_get_tree($vocabulary
        ->id(), $tree['parent'], NULL, TRUE)) {
        foreach ($terms as $term) {
          $options[$term
            ->id()] = str_repeat('-', $term->depth) . $term
            ->label();
        }
      }
    }
  }
  return $options;
}