Skip to content
Snippets Groups Projects

Issue #3393008: :twisted_rightwards_arrows: Fix OptGroupEntityReferenceSelection::getReferenceableEntities() error

1 file
+ 27
12
Compare changes
  • Side-by-side
  • Inline
@@ -61,18 +61,33 @@ class OptGroupEntityReferenceSelection extends TermSelection {
$has_admin_access = $this->currentUser->hasPermission('administer taxonomy');
$unpublished_terms = [];
foreach ($bundle_names as $bundle) {
if ($vocabulary = Vocabulary::load($bundle)) {
/** @var \Drupal\taxonomy\TermInterface[] $terms */
if ($terms = $this->entityTypeManager->getStorage('taxonomy_term')->loadTree($vocabulary->id(), 0, NULL, TRUE)) {
foreach ($terms as $term) {
if (!$has_admin_access && (!$term->isPublished() || in_array($term->parent->target_id, $unpublished_terms))) {
$unpublished_terms[] = $term->id();
continue;
}
$label = Html::escape($this->entityRepository->getTranslationFromContext($term)->label());
if ($term->depth !== 0) {
$options[$vocabulary->id()][$parent][$term->id()] = str_repeat('-', $term->depth - 1) . $label;
}
if (($vocabulary = Vocabulary::load($bundle)) === NULL) {
// Couldn't load vocabulary, so move on to the target bundle.
continue;
}
$terms = $this->entityTypeManager->getStorage('taxonomy_term')->loadTree($vocabulary->id(), 0, NULL, TRUE);
if (!$terms) {
// No terms, so move on to the next target bundle.
continue;
}
$parent = NULL;
foreach ($terms as $term) {
// If there is a reason to not show this term...
if (!$has_admin_access && (!$term->isPublished() || in_array($term->parent->target_id, $unpublished_terms))) {
// ...add it to the list of unpublished terms and move on to the next
// term.
$unpublished_terms[] = $term->id();
continue;
}
$label = Html::escape($this->entityRepository->getTranslationFromContext($term)->label());
// If this is a top level term...
if ($term->depth === 0) {
// ...don't add it to the options, but use it
$parent = $label;
}
else {
if ($parent) {
$options[$vocabulary->id()][$parent][$term->id()] = str_repeat('-', $term->depth - 1) . $label;
}
}
}
Loading