So, let's say I use template.php to override a primary link with some code. Say I want the href or title to be different based on a user. Well, the primary_links array reflects it, but primary_tree does not. Even if I attempt this over-ride in page.tpl.php, same thing happens. Relevant code:
In template.php

  if (in_array(somerole', $user->roles)) {
  $vars['primary_links']['menu-xyz']['href']='path/to/somewhere'
}

In page.tpl.php

print om_menu('main-menu', $primary_links, $primary_links_tree);

This prints the tree, and does not reflect what is in $primary_links

Comments

danielhonrade’s picture

Hi Steve,

Maybe you can override the $vars['primary_links_tree] instead:

<?php
function om_preprocess_page(&$vars) {

// get first the array
$vars['primary_links_array']  = menu_tree_page_data('primary-links');
//dsm($vars['primary_links_array'] );

// manipulate the array
if (in_array('somerole', $user->roles)) {
  $vars['primary_links_array']['1234 home 1234']['link']['link_path']='path/to/somewhere';
}

// rendered menu output
$vars['primary_links_tree']  = menu_tree_output($vars['primary_links_array']);
?>
stkrzysiak’s picture

Daniel,
That works, but then what is the point of the function accepting both variables? Do each serve a purpose?
Thanks

danielhonrade’s picture

Hi Steve,

If I remember it right, I think, I couldn't turn off the the menu links when the theme settings is unchecked using the $primary_links_tree because it's raw, so I also need $primary_links variable for on/off purposes.

And the $primary_links_tree has all the submenus, unlike the $primary_link which has only the top level menu.

danielhonrade’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.