Support hierarchical taxonomy terms and parent selection in SelectTagify widget
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3575938. -->
Reported by: [jansete](https://www.drupal.org/user/1358146)
Related to !202
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>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:</p>
<ol>
<li>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.</li>
<li>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.</li>
</ol>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<ol>
<li>Create a taxonomy vocabulary with a hierarchy (e.g., Parent -> Child).</li>
<li>Configure an entity reference field to use the SelectTagify widget.</li>
<li>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.</li>
</ol>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>The proposed solution involves:</p>
<p>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.</p>
<p>JavaScript (tagify.js):</p>
<ol>
<li>Refactor tagify.dropdown.createListHTML to properly identify terms that are parents.</li>
<li>Implement a mechanism to make parent headers selectable if they exist as actual options in the list.</li>
<li>Use the new data-parent-selection attribute (from the SelectTagify element) to determine if parent selection should be enabled.</li>
<li>Ensure that terms already rendered as group headers are not duplicated in the main list.</li>
</ol>
<p>Form Element (SelectTagify.php): The element now passes the parent_selection property to the frontend via data attributes.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<ul>
<li>Verify compatibility with other Tagify widgets (like EntityAutocompleteTagify) to ensure no regressions in dash stripping.</li>
<li>Test with different levels of nesting in taxonomy.</li>
</ul>
<h3 id="summary-ui-changes">User interface changes</h3>
<ul>
<li>In the SelectTagify dropdown, parent terms can now be rendered as selectable items instead of just plain text labels, provided the configuration allows it.</li>
<li>Improved visual grouping of hierarchical terms.</li>
</ul>
<h3 id="summary-api-changes">API changes</h3>
<ul>
<li>The SelectTagify form element now supports a #parent_selection property (boolean/integer).</li>
</ul>
<h3 id="summary-data-model-changes">Data model changes</h3>
<p>None.</p>
issue