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:
- 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.
- 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
- Create a taxonomy vocabulary with a hierarchy (e.g., Parent -> Child).
- Configure an entity reference field to use the SelectTagify widget.
- 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):
- Refactor tagify.dropdown.createListHTML to properly identify terms that are parents.
- Implement a mechanism to make parent headers selectable if they exist as actual options in the list.
- Use the new data-parent-selection attribute (from the SelectTagify element) to determine if parent selection should be enabled.
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3575938-support-hierarchical-taxonomy-2.patch | 3.9 KB | jansete |
Issue fork tagify-3575938
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
Comment #2
jansete commentedAttach patch.
Comment #3
gxleano commentedThanks @jansete to point this out and fix it.
Could you open a MR with the fix, please?
Comment #4
gxleano commentedComment #6
jansete commentedNow, it's ready, thank you @gxleano.