1

I simply need to change the title on the (Drupal 8.8.4) administrative page which lists the existing vocabularies.

As far as I know/read, the routing.yml should be modified, shouldn't it? (Is only the *defaults_title parameter that needs to be changed?)

Inside the taxonomy.routing.yml file, I only get the form routes for taxonomy term, if I am correct.

Do I need to modify the route elsewhere?

I have tried with the system.routing.yml file, listing many administrative routes (I thought it was the jackpot) but there is no route for the taxonomy page.

Could someone tell me where to go and which static route to change?

Related questions

  • What exactly didn't work with the related questions you linked? – leymannx Mar 30 at 10:31
  • Me :) Actually, examples are nice but I could not figure which entity name, which parameters, etc. I have to work with for Taxonomy page routing. If I could find the code to modify, it would be a start for me. Even if I am more a site builder. – Toki Mar 30 at 10:45
1

Maybe start with https://drupal.stackexchange.com/a/232783/15055, just implement the preprocess page title hook (without the code inside for now) in a custom module or a custom theme.

Then install the Devel sub-module Kint. And put ksm(\Drupal::routeMatch()->getRouteName()); inside this hook. Note, in the hook name replace MYMODULE with your custom module's or theme's machine name.

Then visit the page you want to override the page title from and flush the caches a few times. It now should tell you the name of the route.

Then use this name to build an if-request checking the route's name and replace $variables['title'] with your new title.

/**
 * Implements hook_preprocess_HOOK().
 */
function MYMODULE_preprocess_page_title(&$variables) {
  // ksm(\Drupal::routeMatch()->getRouteName());
  if (\Drupal::routeMatch()->getRouteName() === 'foo.bar.foobar') {
    $variables['title'] = t('My new English title');
  }
}

In the end you could to the same with hook_preprocess_html to replace the meta title by overriding $variables['head_title']['title'] in there.

| improve this answer | |
  • Thanks, it works like a charm. I have edited my question to detail your answer, please review if needed. – Toki Mar 30 at 14:46
  • 1
    @Toki – Kint is THE tool for debugging. It'll probably help you a lot in the future. As a side builder now doing the step to start using hooks. Kint can also be used in templates. With Twig debugging enabled simply put {{ kint() }} and it will tell you what variables and methods you can use in there; and then send new custom variables over to the template using preprocess functions. Have fun! – leymannx Mar 30 at 14:52
1

Could someone tell me where to go and which static route to change?

It's not a static route. Like other entity collection routes, it is built with the aid of the comment annotations above the Vocabulary entity class. VocabularyRouteProvider also comes into play, and it sets a _title_callback into TaxonomyController::vocabularyTitle for good measure.

At any rate, this is all a bit moot because you don't want to go modifying core files, because then when you update core you will have to patch them all over again. Very tedious. Instead you could implement your own RouteSubscriberBase::alterRoutes.

| improve this answer | |

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.