0

When adding terms to a taxonomy vocabulary, the "Parent terms" scrolling selector list in the "RELATIONS" section only displays 4 items. When dealing with large, complex, hierarchical taxonomies, this makes it difficult and slow to find the parent (a similar complaint and another).

I would love to be able to use something like the Simple hierarchical select or Client-side hierarchical select widget there, but assuming that's not currently possible, how can I simply display a longer list to make the selection a bit easier?

I am guessing there is a file somewhere containing a setting of "4" (unless that's a default) that I would able to increase to "20" for example. I hunted but couldn't find it.

I'd be interested in an answer, even if it would be a core hack that I would have to redo with each update.

More items in Parent terms select list

Edit: It seems, from this link, that one solution may involve adding code such as this:

<?php
function MyModuleName_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'taxonomy_form_term') {
    $form['relations']['parent']['#size'] = '20';
  }
}

But where to add it? Or perhaps in a custom module (called MyModuleName)? Perhaps in MyTheme.theme? Or perhaps in a twig file such as html--admin--structure--taxonomy--manage--MyVocabularyName--add.html.twig?

1

OK Nick, you need to add the 'hook' into a custom module.. so for drupal 8 if you do not have a custom module follow the documentation here https://www.drupal8.ovh/.../create-a-simple-module-for... https://www.drupal8.ovh/.../create-a-simple-module-to-use...

In 'modules' folder create a custom folder 'custom' to hold your custom modules. path should be ...modules/custom inside this create a folder folder to hold your custom module my_custom_module ( orwhatever you want to call it ) path should be ...modules/custom/my_custom_module

inside this folder (my_custom_module) add a 'my_custom_module.info.yml' file in this file add

name: My custom module
description: My custom module description
package: Custom

type: module
core: 8.x

run drush en my_custom_module -y or in admin/modules enable the module

once enabled add a .module file to the my_custom_module folder, called my_custom_module.module (or whatever you have called it)

in this file you can add the hooks you want to use for your one it will be

<?php
function my_custom_module_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'taxonomy_term_vocabulary_name_form') {
$form['relations']['parent']['#size'] = '15';
}
}

change the my_custom_module to whatever you have called your module change the section of the form id == vocabulary name to the name of the vocab you have created, you may need to inspect this and find it the form id! mine matched the vocab

clear the cache, go to your vocabulary and add a new term ! fingers crossed the size of the selct box has changed

think this covers it all, good luck

  • As an addendum, $form['relations']['#open'] = TRUE; can be added to that function so the form opens by default. Furthermore, if you have the Chosen module installed, then it can "take over" that widget and act as a combo of drop-down scrolling select list and auto-complete widget, making it much easier to select parent terms in a large vocabulary. If you both add that line and have Chosen installed, then you can remove the '#size' line from the function, since it doesn't have an affect. – Nick Hope Jan 23 '18 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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