1

Problem

I'm trying to set-up an Authcache customised menu.

The first way of doing it would be to create 3 menus, one for each of my roles and one for anon then create a custom tpl.php for each using the user_link and user_name variables.

(These variables are provided by the user example module in authcache to all templates.)

Block logic would then give the correct user the correct menu.

It seems a little clumsy.

Is it possible to grab the links inside template.php and use user_link and user_name variables there because I can't find a function which has the links available.

Or how has anyone else solved this problem?

0

In the context of a preprocess hook, yes:

function MYTHEME_preprocess_foo(&$vars) {
  $user_link = $vars['user_link'];
}

Outside of that context I guess you could invoke authcache_usercookie_preprocess() manually:

$vars = array('user' => $GLOBALS['user']);
authcache_usercookie_preprocess($vars, NULL);
$user_link = $vars['user_link'];
  • Cheers Clive. I'd been trying to use MYTHEME_preprocess_menu_tree which I couldn't get to work for some reason. – Dominic Woodman Dec 12 '13 at 11:12
  • Hmm so in my arrogance I may have prematurely posted my answer. I thought changing the href in the MYTHEME_preprocess_page would change the rendered HTML, but it doesn't. I thought preprocess_page happened before theming? Am I missing something obvious? – Dominic Woodman Dec 13 '13 at 16:10
  • Yes I was, I'd been outputting the menu as a block, as opposed to a variable from page.tpl.php. Apparently 4 months I couldn't get enough of blocks. – Dominic Woodman Dec 13 '13 at 17:04
1

Ok so here is my solution.

Menu's are themed in MYTHEME_preprocess_page, the menu data is also still structured here unlike in MYTHEME_preprocess_menu_tree.

I enabled the memcached example module, this enables the variables user_link and user_name in the preprocess. Then I created a third variable user_account just copying from the other two and altered the cookie so it stores uid not name.

This is because I wanted the "My Account" link to link to "user/x/edit" and I didn't need the name.

I then added the following chunk to my page preprocess.

function MYTHEME_preprocess_page (&$vars) {
  $user_account = $vars['user_account'];
    if (array_key_exists('menu-xxxx', $vars['secondary_menu'])) { 
      $vars['secondary_menu']['menu-xxxx']['href'] = $user_account; 
    }

The secondary menu in this case is my user menu and My Account is always labelled menu-xxxx in the array. (xxxx will be numbers).

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.