0

The Taxonomy relations > Parent terms select list is lengthy to look through so ideally we'd like a Hierarchical select list. We already use the Client-side hierarchical select module for other fields, but it doesn't appear to be designed for this particular field. Is there a way for me to programmatically apply the module to this field by altering the form in hook_form_alter()?

Picture of Parent terms select list

We've considered using the Chosen module but an autocomplete isn't exactly the functionality we're hoping for. I also understand there's the Simple hierarchical select module, but since we already use CSHS, I wasn't sure if it was advisable to have both CSHS and SHS. For the time being we've changed ['#multiple'] = false; to turn it into a basic drop-down.

1
  • ['#multiple'] = false; is not working anymore, if so I get the error TypeError: array_values(): Argument #1 ($array) must be of type array, string given in array_values() (line 155 of core/modules/taxonomy/src/TermForm.php). Is there a other way to disable multiple values?
    – LarS
    Commented Jun 13 at 15:27

1 Answer 1

0

Chosen's autocomplete is just a bonus. You can have your normal hierarchy using chosen and it is much more accessible than other options you have. I would at least give it a go.

Now considering SHS and CSHS.. they are quite similar and I would not recommend using them side by side.

The main reason for that is that they tackle the same issue with a different approach and -best case scenario- one's functionallity would overwrite the other's.

Now as far as I know they do indeed have compatibility issues as stated in CSHS's module page (at the time this was posted)

It is possible to use the CSHS widget as an exposed filter for taxonomy term reference fields. Please note that this feature might break if SHS module is enabled on your site.

While I think I find CSHS's approach more usable, I would stick with SHS and chosen in your case since you mentioned that your vocabularies are large and CSHS, being client side and all, is more susceptible to performance issues, since it

[...], but in contrast to those modules the whole taxonomy tree is already present at page-load and the whole processing is done "client-side".

Now, to give the devil it's due, both modules have performance issues with very large trees and it is only natural and understandable, but SHS seems like a more stable choice.

Lastly, to achieve what you described, I would prefer a more "Drupal 8" way and would create a new Field Formatter plugin for the entity reference field you are using and attach this to the form in the form display tab of you entity.

To summarize, I would but not use SHS in conjunction with CSHS, and although you have to try it our yourself, the combination of SHS and Chosen seems to me like the obvious choise for your case. Try overriding the entity reference field's field formatter to add the taxonomy parent name to your options if you prefer a more custom approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.