3
votes

I have a Drupal 8 page views with contextual filter, and path of the same is like:

/category/%cid/product/%pid

Here %cid and %pid are contextual filters of the page view.

In this page, I want to change my footer menu, to alter the links so that:

/privacy-policy 

becomes

/productname/privacy-policy

only if any node created and it has url path settings:

/productname/privacy-policy

How to achieve this.

Note: based on the discussion in Drupal I tried,

  • To alter routes, implement a RouteSubscriber
  • To alter menu links, use hook_menu_links_discovered_alter()

I can not achieve this.

1

1 Answers

1
votes

I'm trying to achieve similar thing by using hook_menu_links_discovered_alter() and it generally works:

  function mymodule_menu_links_discovered_alter(&$links) {
      $links['linkid']['title'] = 'Some new title';
      $links['linkid']['url'] = 'http://www.google.com';
    }

link title and url is changed. But problem I'm facing is that those changes are heavily cached. I.e. if I set title depending on current language title will be correct for the first visit but that title will be remembered and used for each visit after that. So when I switch language title will remain the same (cached one).