public function TermSelection::getReferenceableEntities in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php \Drupal\taxonomy\Plugin\EntityReferenceSelection\TermSelection::getReferenceableEntities()
Gets the list of referenceable entities.
Return value
array A nested array of entities, the first level is keyed by the entity bundle, which contains an array of entity labels (escaped), keyed by the entity ID.
Overrides DefaultSelection::getReferenceableEntities
File
- core/
modules/ taxonomy/ src/ Plugin/ EntityReferenceSelection/ TermSelection.php, line 61 - Contains \Drupal\taxonomy\Plugin\EntityReferenceSelection\TermSelection.
Class
- TermSelection
- Provides specific access control for the taxonomy_term entity type.
Namespace
Drupal\taxonomy\Plugin\EntityReferenceSelectionCode
public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
if ($match || $limit) {
return parent::getReferenceableEntities($match, $match_operator, $limit);
}
$options = array();
$bundles = $this->entityManager
->getBundleInfo('taxonomy_term');
$handler_settings = $this->configuration['handler_settings'];
$bundle_names = !empty($handler_settings['target_bundles']) ? $handler_settings['target_bundles'] : array_keys($bundles);
foreach ($bundle_names as $bundle) {
if ($vocabulary = Vocabulary::load($bundle)) {
if ($terms = $this->entityManager
->getStorage('taxonomy_term')
->loadTree($vocabulary
->id(), 0, NULL, TRUE)) {
foreach ($terms as $term) {
$options[$vocabulary
->id()][$term
->id()] = str_repeat('-', $term->depth) . Html::escape($term
->getName());
}
}
}
}
return $options;
}