dear list

im trying to overwrite the function theme_menu_item() for a specific block region
say i have the block-regions header, left, right, footer
and only want to change the html for the menu-items which are assigned to the header-block

any idea how to do this ?
thanx in advance

Comments

robwilmshurst’s picture

I'm also looking for information on how to do this... I'll post back here if I find anything...

dvessel’s picture

What are you trying to change in the list item? Depending on what you want out of that you could simply add a class to block.tpl.php and work through css.

An alternative would be to override theme_blocks() --plural and set a global for the current region. Since the all the blocks are invoked from there any other function that comes after it should know it's current region.

Inside template.php:

function phptemplate_blocks($region) {
  // Set global to be read elsewhere.
  global $_current_region;
  $_current_region = $region;

  // invoke usual function.
  $output = theme_blocks($region);

  // Reset to null so we don't get a false reading.
  $_current_region = NULL;

  return $output; 
} 
function phptemplate_menu_item($mid, $children = '', $leaf = TRUE) {
  global $_current_region;
  // Make sure it's not NULL and we are in the right region.
  if (isset($_current_region) && $_current_region == 'REGION_NAME') {
    // YOUR CODE
  }
  return '<li class="'. ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .'">'. menu_item_link($mid) . $children ."</li>\n"; 
} 

I haven't tested but I'm pretty sure it should work.

kabaman’s picture

thats exactly what i was looking for
i just tried the first part/code

thanx

melchior’s picture

hi,
thx for your great solution!!

But if I try the code it always renders menu only once with "left" as current region :(
I really set the block to another regions...

If I skip left by following row, it renders menu again only once at next region in list :(
### if ($region =="left" || $region =="right" || $region =="top" || $region =="footer" ) return;

whats going wrong there? The menu always gets rendered single time at first matching
although there shouldn't be rendered any content..

would be aweful to get some help,
I really need this function :D

greets,
melchior

noah’s picture

This is a great solution, and I've used it a lot over the past few years in Drupal 6 sites. However, "theme_blocks" doesn't exist in Drupal 7, so it doesn't work any more. Does anyone have any ideas for accomplishing the same thing in Drupal 7?

noah’s picture

Bumping this in hopes of attracting the attention of someone with an idea -- does anyone know how to get the current region from within theme_menu_link() in D7?

kumkum29’s picture

Have you found a solution?

Thanks.

blast0344’s picture

Here is solution: http://drupal.stackexchange.com/a/219770/32059

I had same problem and I've found it now.