4

The site I am building uses fields (plus a custom module) to provide a richer set of relationships between taxonomy terms than the built-in hierarchy allows.

I want to remove/disable the built-in hierarchy. What I mean is that when a user is creating or editing a term, I do not want them to see the "Relations" section, and when they are viewing a list of terms in a taxonomy, I want the drag-and-drop functionality to only work for ordering, not indenting.

I know I can do this with another module using hook_form_alter() or the like, but is there an easier and quicker way to "turn off" this functionality in Drupal 8? I have a vague memory of (maybe in an earlier Drupal, or somewhere else) being able to specify, when you create a taxonomy, if you want it to be hierarchical or not, but I cannot find such a thing here.

3 Answers 3

1

UPDATE

You can also use Flat Taxonomy module, this will get rid off both the parent and the drag-n-drop. Also if you enable it for an existing vocabulary with terms with hierarchy, it will flatten the tree for you. Bare in mind that the panel "Relations" keeps showing since contains the "Weight" field. If you plan using this module check the opened issues #3115794 and #3012578 since you need does patches in order to work.

Original answer

You can use Taxonomy Max Depth module, even though it does not get rid off the "Relations" panel validates the input, and also prevents the drag-n-drop on the terms overview. For a better results in terms of UX you can also hide the panel using the hook_form_alter as mentioned (I don't know how to achieve the same for the drag-n-drop other than replacing the view).

0

If the Relation input is not exposed in the Form Display, then you are going to need to use a hook_form_alter to hide the Relation input.

Also, note, that the drag and reorganize on the vocabulary overview will still support hierarchy. You'll need to alter that form as well to disable it.

0
0

You can add something like this in your custom module.

/*
 * Implements hook_form_BASE_FORM_ID_alter() for the taxonomy term form.
 */
function mymodule_form_taxonomy_term_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $form['relations']['parent']['#options'] = [0 => '<root>'];
    
  if (\Drupal::state()->get('taxonomy_test.disable_parent_form_element', FALSE)) {
    $form['relations']['parent']['#disabled'] = TRUE;
  }
}

If you have a huge vocabulary, now it should load a bit faster, although the back-end is still calling TermStorage::loadTree(), which uses a lot of RAM. You will need to patch it to prevent loading the tree and reduce your RAM usage for very large vocabularies.

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.