public function TermSelection::getReferencableEntities

Overrides SelectionBase::getReferencableEntities().

Overrides SelectionBase::getReferencableEntities

File

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/entity_reference/selection/TermSelection.php, line 56
Contains \Drupal\taxonomy\Plugin\entity_reference\selection\TermSelection.

Class

TermSelection
Provides specific access control for the taxonomy_term entity type.

Namespace

Drupal\taxonomy\Plugin\entity_reference\selection

Code

public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
  if ($match || $limit) {
    return parent::getReferencableEntities($match, $match_operator, $limit);
  }
  $options = array();
  $bundles = entity_get_bundles('taxonomy_term');
  $bundle_names = !empty($this->instance['settings']['handler_settings']['target_bundles']) ? $this->instance['settings']['handler_settings']['target_bundles'] : array_keys($bundles);
  foreach ($bundle_names as $bundle) {
    if ($vocabulary = entity_load('taxonomy_vocabulary', $bundle)) {
      if ($terms = taxonomy_get_tree($vocabulary
        ->id(), 0)) {
        foreach ($terms as $term) {
          $options[$vocabulary
            ->id()][$term
            ->id()] = str_repeat('-', $term->depth) . check_plain($term->name);
        }
      }
    }
  }
  return $options;
}