2

I am using a custom way of managing relations between terms in a particular vocabulary so I want to disable (or at least hide) the built-in functionality allowing terms to be placed in a hierarchy.

I have managed this to some extent with CSS (managed by the module that also does the custom relations). I have removed the "Relations" section from the taxonomy term edit form and I have removed the handles from the vocabulary list so that you cannot move the terms around and place them in a hierarchy that way. But I cannot see how to get rid of, or alter, the help text which says "You can reorganize the terms in Topic using their drag-and-drop handles, and group terms under a parent term by sliding them under and to the right of the parent.".

The problem is that there are no containers around this to identify which vocabulary is being adminstered, or indeed that it is on a taxonomy vocabulary list page at all. I have read the Drupal 8 docs on attaching libraries and they all say that targeting pages by URL is deprecated.

I suspect hook_form_alter would not work either as it is outside of the form tags.

Is there any way to do this?

1
  • Worst case scenario, you can deal with this in a non drupal way. You can use CSS to remove it or jQuery to remove or alter it.
    – No Sssweat
    Jul 27, 2017 at 1:26

3 Answers 3

3

When creating a vocabulary you have the option of turning on/off the ability to arrange terms in a hierarchy. If you choose "Single Hierarchy" for example then the help text will change to read: "VOCAB contains terms grouped under parent terms. You can reorganize the terms in VOCAB using their drag-and-drop handles."

See http://cgit.drupalcode.org/drupal/tree/core/modules/taxonomy/taxonomy.module#n78

... Otherwise you can create a custom module that implements hook_help and check for $route_name = entity.taxonomy_vocabulary.overview_form. As long as your module's hook_help fires after taxonomy_help() your's should win. See https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension%21module.api.php/function/hook_module_implements_alter/8.4.x to control whose module wins when implementing a hook

3
  • Thanks but I think the first part of this answer is incorrect. I don't think there is any option to disable hierarchy. The code that you link to has different help text for didn't scenarios, but the "hierarchy_disabled" scenario just means that terms have not been arranged into a hierarchy. It doesn't mean the ability to do so is disabled. This is clear from the help text itself, which tells you how to put the terms into a hierarchy.
    – naomi
    Jul 27, 2017 at 6:30
  • I tried the second suggestion (hook_help) but it appends to the original help text, rather than replacing it.
    – naomi
    Jul 27, 2017 at 8:29
  • Voted up because this helped me onto the right track. Posted my working solution as answer
    – naomi
    Jul 27, 2017 at 11:32
0

I ended up achieving this in a rather round-about way but I could not see a more straightforward way to do it.

Following the second part of bleen's answer I looked at hook_help but I found that this appended my text to the default help text, rather than replacing it.

To hide the default help text and "replace" it with my own, I did this:

First, in the php for my module, I used hook_module_implements_alter in order to place my implementation, not last as bleen suggests, but first, so that the html it generates appears before the default help text:

function topic_relations_module_implements_alter(&$implementations, $hook) {
 if ($hook == 'help') {
    $implementations = array('topic_relations' => $implementations['topic_relations']) + $implementations;
  }
}

Then I specified the help text, with an id for ease of css selection:

function topic_relations_help($route_name, $route_match) {
  if  ($route_name == "entity.taxonomy_vocabulary.overview_form") {
    return "<p id='replacement_taxonomy_help'>The default functionality for arranging terms into a hierarchy has been overridden by the custom module 'Topic Relations'. </p>";
  }
}

Then in the css I used the sibling selector to hide the paragraph that comes after the one I inserted. (There is no previous-sibling selector, which is why I had to mess with the order of implementation).

#replacement_taxonomy_help ~ p { 
  display: none;
}
0

My solution is similar to the one of naomi, but it removes the help text instead of hiding it, see following example code from MY_MODULE.module.

Example: Removing help text of block_content module for the route entity.block_content.collection:

/**
 * Implements hook_module_implements_alter()
 */
function MY_MODULE_module_implements_alter(&$implementations, $hook) {   
  // Don't invoke block_content_hook(), to not show help texts from that module.
  if ($hook === 'help' && isset($implementations['block_content'])) {
    unset($implementations['block_content']);
  }
}

/**
 * Implements hook_help().
 */
function MY_MODULE_help($route_name, RouteMatchInterface $route_match) {
  // Re-add all help text from block_content_help() except for route
  // entity.block_content.collection.
  if ('entity.block_content.collection' !== $route_name) {
    return block_content_help($route_name, $route_match);
  }
}

There is a drupal.org issue for that, see Allow for altering help displayed by other modules. But as stated there:

it seems that hook_help() is likely to get deprecated, even if there is no definitive decision yet (see #3031642: Deprecate hook_help() and combine with Topics).

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.