Note that there are some explanatory texts on larger screens.

plurals
  1. POHide menu link for particular referrer in Drupal 7
    primarykey
    data
    text
    <p>I'm looking for a way to hide specific menu items for anonymous users under certain conditions. In particular, I serve a site for affiliates on several subdomains, and for certain subdomains (affiliates) I would like to hide the link to my 'about us' page which appears in a couple of menus.</p> <p>I'm not overly bother about completely denying access to the 'about us' node, but appreciate that this might be one avenue to explore.</p> <p>So far I've looked at: * hook_menu_alter but this is only called when the menu tree is rebuilt and also I can't see how I would remove items only for a particular anonymous session. * template_preprocess_menu_link : possible, but how to I tell the item not to render. I could add a class to the menu item that hides it, not particularly nice but it would work. * hook_node_access : can't see how I would prevent access for only this session.</p> <p>Any thoughts or pointers welcome.</p> <p>[Edit] To follow up on this, I have a solution working, but I'm not at all proud of it, there must be a nicer way. I'm using the 'hidden' class to add a css 'display:none' attribute to the list item.</p> <pre><code>function sil_affiliate_preprocess_menu_link(&amp;$variables) { $affiliate = get_affiliate_from_session(); if ($affiliate &amp;&amp; !$affiliate-&gt;show_aboutus) { $real_path = drupal_lookup_path('source','customerservice/aboutus'); if ($variables['element']['#original_link']['link_path'] == $real_path) { $variables['element']['#attributes']['class'][] = 'hidden'; } } } </code></pre> <p>:wq Familymangreg.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload