Show Hide Menu based user location

Created on 22 September 2024, 7 months ago

Problem/Motivation

Hi Everyone, I have a scenario where I have a custom menu> Test > Child 1> Child 2> Child 3> Child 4> Child 5. These childs are dynamic. Childs are created whenever we save a node of type notify. Now this node has a location field and user also has location field.
My requirement is whenever user login to the application, he should see the Childs whose location is same as user location.

I have tried to use hook_preprocess_menu but when I dump its showing in admin login.But same dump is not working in customer user login.

Please provide me a solution. Thank you!

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

📌 Task
Status

Active

Version

10.3

Component

menu system

Created by

🇮🇳India sirishasingampalli Visakhapatnam, Andhra Pradesh

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @sirishasingampalli
  • 🇮🇳India sirishasingampalli Visakhapatnam, Andhra Pradesh
  • 🇳🇿New Zealand quietone

    @sirishasingampalli, as you can see by the lack of response the Drupal Core issue queue is not the ideal place for support requests. The 'support request' option is there for filing support issues for contributed modules and themes. There are several support options listed on our Support page . This is 'Get Support' at the top of Drupal.org. There is also information about Drupal Slack , at 'Get Support -> Drupal Slack' also at the top of Drupal.org. You may get better replies in one of those places.

  • 🇮🇳India r.shaikh Pune

    Hello @Sirisha,

    Try with hook_preprocess_block() and find you custom menu block then try to dump the $menu_tree, find below code snippet.
    Hope this will work.

    
    function hook_preprocess_block(&$variables)
    {
    
      // Identify the block you want to modify.
      $block_id = $variables['elements']['#plugin_id'];
    
      // Check if this is the block you want to target by its machine name.
      if ($block_id == '<machine_name>') {
        $menu_tree = $variables['content']['content']['#tree'];
     }
    
    }
    
  • 🇺🇸United States smustgrave

    This kind of question is probably more suited for forum like stackoverflow, as mentioned in #4

    Thanks @r.shaikh for answering though.

Production build 0.71.5 2024