Problem/Motivation

Currently, the SelectTagify widget does not correctly handle hierarchical taxonomy terms when used in conjunction with the grouping logic in tagify.js. Specifically, two issues were identified:

  1. The tagify_options_list_alter function was stripping the dashes (hierarchical indicators) from the options even for the tagify_select_widget. This prevents the JavaScript logic from identifying the hierarchy level of the terms.
  2. The tagify.js dropdown generation logic (createListHTML) was grouping terms by parent but didn't allow the parent term itself to be selectable if it was also a header for a group. Additionally, there was no way to toggle whether parent terms should be selectable.

Steps to reproduce

  1. Create a taxonomy vocabulary with a hierarchy (e.g., Parent -> Child).
  2. Configure an entity reference field to use the SelectTagify widget.
  3. In the form, observe that the dropdown groups terms but the parent terms are often displayed only as non-selectable headers, and the hierarchy indicators (dashes) might be missing or processed incorrectly for this specific widget type.

Proposed resolution

The proposed solution involves:

PHP (tagify.module): Update tagify_options_list_alter to skip the dash-stripping process for the tagify_select_widget. This allows the widget to receive the raw labels (with dashes) which are necessary for the hierarchical logic in the frontend.

JavaScript (tagify.js):

  1. Refactor tagify.dropdown.createListHTML to properly identify terms that are parents.
  2. Implement a mechanism to make parent headers selectable if they exist as actual options in the list.
  3. Use the new data-parent-selection attribute (from the SelectTagify element) to determine if parent selection should be enabled.
  4. Ensure that terms already rendered as group headers are not duplicated in the main list.

Form Element (SelectTagify.php): The element now passes the parent_selection property to the frontend via data attributes.

Remaining tasks

  • Verify compatibility with other Tagify widgets (like EntityAutocompleteTagify) to ensure no regressions in dash stripping.
  • Test with different levels of nesting in taxonomy.

User interface changes

  • In the SelectTagify dropdown, parent terms can now be rendered as selectable items instead of just plain text labels, provided the configuration allows it.
  • Improved visual grouping of hierarchical terms.

API changes

  • The SelectTagify form element now supports a #parent_selection property (boolean/integer).

Data model changes

None.

Issue fork tagify-3575938

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jansete created an issue. See original summary.

jansete’s picture

Status: Active » Needs review
StatusFileSize
new3.9 KB

Attach patch.

gxleano’s picture

Thanks @jansete to point this out and fix it.

Could you open a MR with the fix, please?

gxleano’s picture

Status: Needs review » Needs work

jansete’s picture

Status: Needs work » Needs review

Now, it's ready, thank you @gxleano.