Incorrectly structured HTML for the term tree list

Created on 3 November 2021, about 3 years ago
Updated 3 April 2024, 9 months ago

Problem/Motivation

There is a problem with the term tree list that is displayed using the Term Reference Tree display widget. The structure of the nested unordered lists that display child terms is badly formed. For example, I have a node that displays a term tree list where the term relationships are:

- Grandparent term
-- Parent term
--- Child term

One would expect the structure of the HTML for the term tree list to be something like

<div class="item-list">
  <ul class="term">
    <li>
      <div>Grandparent term</div>
      <div class="item-list">
        <ul class="term">
          <li>
            <div>Parent term</div>
            <div class="item-list">
              <ul class="term">
                <li>
                  <div>Child Term</div>
                </li>
              </ul>
            </div>
          </li>
        </ul>
      </div>
    </li>
  </ul>
</div>

In this unordered list, there is one list item at each level, matching the structure of the taxonomy terms. Instead, the module outputs code that looks like:

<div class="item-list">
  <ul class="term">
    <li>
      Grandparent term
    </li>
    <li>
      <div class="item-list">
        <ul class="term">
          <li>
            Parent term
          </li>
          <li>
            <div class="item-list">
              <ul class="term">
                <li>Child Term</li>
              </ul>
            </div>
          </li>
        </ul>
      </div>
    </li>
  </ul>
</div>

As you can see, there are two list items at the top two levels: one for the term and an "empty" item for the list of children.

The culprit here seems to be the _term_reference_tree_output_list_level() function starting line 525 of the term_reference_tree.module file. This function is creating an items list where a term and its children are two separate items. They really should be one item containing both the term link and the list of children.

I don't know how to code this behavior, otherwise I would have provided a suggestion or a patch. I believe other lists generated by Drupal, like menus, correctly build unordered lists. So it should be possible.

πŸ› Bug report
Status

Needs review

Version

1.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States aaronpinero

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States fallenturtle

    This solution is also working for me. I'm not sure what's the status of the PR, but its been two years, so I made a patch for others convenience.
    Thanks aaronpinero!

Production build 0.71.5 2024