How to display certain links in a menu only if a precondition is met?


First of all you need to store value of 'For Test User' checkbox as variable OR as separate column in menu_links table.

like variable_set(url, checkbox_value);

By using hook_menu_alter you can check the variable is set for that url. and if its not set you can set $items['url']['access callback'] = FALSE, By setting this menu will not be visible.

Let me know if anything different required.

Tags: Drupal 8

Similar questions

Rules module doesn't send emails to user roles once conditions are met
I'm working in drupal 7 and I've configured the rules module to send emails you specific user roles when content is created. For some reason I'm getting inconsistent results, sometimes not receiving any emails. Any insight to why rules isn't generating emails would be helpful. Here's my Rule:
How to select nodes of a certain type, created by a certain user and which have reference field to a node equal a certain nid?
I need a function that lists nodes by following this logic: give me all nodes of a given type which are created by a given user and which have a node reference field referencing a given node id. Any ideas about such function (in PHP, not in Views) )?
Show block menu links only on certain pages
I've built a menu with 20 links aprox. Then I put the block drupal creates for my menu on a region. Thing is I want some of the links to show for some pages, while others are hidden, like the option called "visibility options" on admin/structure/block/manage/block/nodenumber/ i.e.: links 1,2 and 3 should be visible on page node/1 links 1,3 and 5 sh...
How do you give permissions to certain roles to get certain menu items to display in the admin_menu toolbar?
Currently I'm using the admin_menu module and have certain roles restricted todo certain things. As an admin I can see the full admin_menu bar in full, but as a restricted user I can only see Add content. Since I'm running the commerce module, I only want certain roles to get the Store dropdown menu. Right now I only see Add content and I'm not sur...
How to make all menu links without www? (shortened menu links)
I've seen a few sites, not necissarily Drupal sites, in which the menu links, are without www. (that is the Cname DNS record). Drupal 7 shortens links from to be I am asking if it is possible to create links without the Cname even, I.E that the final result would be: Can be done from inside the Drupal ...
How to allow the translation of menu links provided by
I have the Configuration Translation module installed in a multilingual site and I am able to translate any menu created with the UI.... This is fine!! I have a module which is creating some menus with the help of a yml static file: Unfortunately, 1-I couldn't translate any title/description (created in the yml) through in ...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.