Tree is empty when allowed terms are not on first level

Created on 29 June 2023, over 1 year ago
Updated 14 May 2024, 6 months ago

Problem/Motivation

When using the '#allowed' key to limit the terms in the tree, if the allowed items are not on first level, then the resulting tree is empty.

Steps to reproduce

Add a vocabulary with 1 top level term and a child term.
Add a field that references the vocabulary and set Term Reference Tree as the form widget for the field.
From code, use the form alter hook to add the child term to the '#allowed' list for the field.

Expected result: Only the child term is displayed.
Actual result: Term tree is empty.

Proposed resolution

The method _term_reference_tree_get_term_hierarchy only checked the allowed list against top level terms. I added an else clause where it looks for the allowed term id in the top level terms to manually load the term if it is doing the initial load of terms.

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡·πŸ‡΄Romania bogdan.dinu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024