Hello
How I can override replaced theme function by DHTML Menu module in my template.php file?
I need to override function:

function dhtml_menu_theme_menu_item_link($link) {
...
}

When I tried to override this like:

function phptemplate_dhtml_menu_theme_menu_item_link($link) 
or
function dhtml_menu_MyThemeName_menu_item_link($link) {

I does not give me any effect.

Thank you.

Comments

cburschka’s picture

Status: Active » Closed (works as designed)

There is a misunderstanding. DHTML Menu's functions are not theme functions and cannot be overridden. They themselves override theme functions.

I am sorry, but it is impossible to affect these functions without editing the files directly.

cburschka’s picture

Title: override module function » Allow theming of menu_item_link and menu_item
Version: 6.x-3.0-beta » 6.x-3.x-dev
Category: support » feature
Status: Closed (works as designed) » Active

Hey, now I understand what you want - you need to override the functions yourself, but cannot because the module hijacks them and then directs to the base theme function. Instead of calling the base function, I could call the overriding function if one exists.

light9’s picture

Yes, thank you. I just need to add to my links in navigation menu few attributes: class="ajax" name="ajaxify". I made it by deleting dhtml_menu_theme_menu_item_link function from dhtml_menu.module and add this edited function in my template.php file:

function dhtml_menu_theme_menu_item_link($link) {
  // The ID is the mlid or a stripped form of the link path. It just must be unique.
  $id = isset($link['mlid']) ? $link['mlid'] : preg_replace('/[^a-z0-9]/', '0', $link['href']);
  $link['localized_options']['attributes']['id'] = "menu-". $id;
  $link['localized_options']['attributes']['name'] = "ajax";
  $link['localized_options']['attributes']['class'] = "ajaxify";

  // Each link in series is another level of recursion. Add it to the stack.
  _dhtml_menu_stack($link);

  // Pass the altered variables to the normal menu themer.
  return theme_menu_item_link($link);
}

I just want to keep module files clean and not edited for future upgrading and make all overriding in me theme files.
Thank you.

cburschka’s picture

Will do. I'm working on the feature right now.

If devel_themer can do it, so can I - in fact, I have it a lot easier since I just need to dispatch and not intercept all kinds of information.

cburschka’s picture

Status: Active » Needs review

This works for me. Please test it with your set-up too, to make sure I didn't miss anything.

Before the module replaces the theme function "theme_menu_item" (which could already have been overridden with "garland_menu_item") it now stores the original function name, and calls that after doing its interception work. So you can override this function in the theme layer and know that eventually it will get called.

cburschka’s picture

StatusFileSize
new1.76 KB

Hah.

Not THAT again. I hate it when d.o doesn't save the attachment.

cburschka’s picture

StatusFileSize
new1.76 KB

Hah.

Not THAT again. I hate it when d.o doesn't save the attachment.

cburschka’s picture

LOL! And now it saved it twice to make up for it. =D

cburschka’s picture

I'd like some feedback before I commit this to a production branch.

light9’s picture

Hi. I'am sorry for delay in answer.
It works!
I upgraded module to 6.x-3.2, patched it and tried to add in my template.php this:

function phptemplate_menu_item_link($link) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
    $link['localized_options']['attributes']['name'] = "ajax";
  }
  if (empty($link['localized_options']['attributes']['class'])) {
    $link['localized_options']['attributes']['class'] = 'menu-'. $link['mlid'];
    $link['localized_options']['attributes']['name'] = "ajax";
  }
  else {
    $link['localized_options']['attributes']['class'] .= ' menu-'. $link['mlid'];
    $link['localized_options']['attributes']['name'] = "ajax";
  }
  return l($link['title'], $link['href'], $link['localized_options']);
}

And theme output changed. I need all this changes to ajaxify my theme and use it together with this great module.
Thank you for this nice module and your support!
I will follow with updates.

cburschka’s picture

Version: 6.x-3.x-dev » 7.x-1.x-dev
Status: Needs review » Patch (to be ported)

Thank you very much for your feedback! :)

I've committed this patch to DRUPAL-6--3 now. I'll wait for a week or so for users of 6.x-3.x-dev to complain about potential problems before I'll release it as stable.

In the meantime, I need to port this to Drupal 7.

cburschka’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new2.16 KB

Here we go.

cburschka’s picture

Status: Needs review » Fixed

Committed to HEAD.

Status: Fixed » Closed (fixed)

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