I want to create a customized media library for my editors, with a tab navigation similar to the tabs on core's admin/content view. It basically works, but I also want to add a tab leading to a specific "media" taxonomy vocabulary used by my media entities. As soon as I add the taxonomy tab to my YML file, the base_route filter no longer works.

Screenshot with correct behaviour on view pages: Works correctly on view page

Screenshot with unwanted tabs on taxonomy page: Unwanted tabs on taxonomy page This is my custom modules' links.task.yml.

# a common view page for all media types
  route_name: view.medialibrary.medialibrary
  base_route: view.medialibrary
  title: 'All media types'
# a view page only for images
  route_name: view.medialibrary.imagelibrary
  base_route: view.medialibrary
  title: Images
# a view page only for videos
  route_name: view.medialibrary.videolibrary
  base_route: view.medialibrary
  title: Videos
# a view page only for documents/files
  route_name: view.medialibrary.filelibrary
  base_route: view.medialibrary
  title: Documents
# as soon as I activate the following entry, all the tabs are shown
# on every taxonomy overview page, this is not wanted
  route_name: entity.taxonomy_vocabulary.overview_form
    taxonomy_vocabulary: media
  base_route: view.medialibrary
  title: Manage Categories

How can I prevent my custom tabs from appearing on the taxonomy overview pages?


You can use hook_menu_local_tasks_alter() to see what all elements are added and can remove elements based on any conditions you like.

| improve this answer | |

To completely remove the tab from all pages you can use hook_local_tasks_alter().

You can use it like this:

function mymodule_local_tasks_alter(&$local_tasks) {

Where local_task_to_remove is the tab you want to remove.

To have it removed from some pages only you could use hook_menu_local_tasks_alter() instead.

Like this:

function mymodule_menu_local_tasks_alter(&$data, $route_name) {
  $routes = ['entity.entity_view_display.node.default', ...]; // put other routes in place of '...'
  if (in_array($route_name, $routes)) {
| improve this answer | |
  • I know that I could use this hook, but doing it in YML feels like a cleaner solution and I'd like to know why my YML solution doesn't work as expected. The base_route of wt_media.manage_taxonomy is obviously different than any taxonomy route, yet it shows up there... – Hudri Mar 26 '18 at 9:16
  • Yes I see, and it looks strange. The media_taxonomy route, is that the place where you want your tabs to show up? – user72672 Mar 26 '18 at 9:20
  • @Hudri Everywere I look it seems that this solution is the best – user72672 Mar 26 '18 at 9:31
  • I want all 5 tabs (only!) on the view pages (see route_name of the first 4 entries, they are all different page displays of the same view). – Hudri Mar 26 '18 at 9:32
  • I cant actually se any problems with your code – user72672 Mar 26 '18 at 9:54

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.