One of my users has a separate theme chosen other than the default system theme. When going through the site he continually sees this error:

warning: call_user_func(mytheme_menu_item_link) [function.call-user-func]: First argument is expected to be a valid callback in C:\opt\www\ mysite\sites\all\modules\special_menu_items\special_menu_items.module on line 101.
warning: call_user_func(mytheme_menu_item_link) [function.call-user-func]: First argument is expected to be a valid callback in C:\opt\www\ mysite\sites\all\modules\special_menu_items\special_menu_items.module on line 101.

I think the module tries to rely on the default theme. When this user used the Garland theme, special_menu_items tried to call the default theme's menu_item_link function instead of Garland's and it all went downhill.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

redijedi’s picture

Priority: Normal » Critical

I forgot to mention that it prevents the rendering of the menu task items on the user-chosen theme. That's a pretty big problem.

jnpWebDeveloper-1’s picture

Hi,

great module by the way - simple and very usefull. However I have exactly this issue but I use a default theme and garland as admin theme. Now I use _menu_item_link to modify output of the tabs on node edit pages but this causes the same error as above and I don't know how to fix it. Here is the script form template.php:

function themex_menu_item_link($link) {
  if (empty($link['options'])) {
    $link['options'] = array();
  }

  // If an item is a LOCAL TASK, render it as a tab
  if ($link['type'] & MENU_IS_LOCAL_TASK) {
    $link['title'] = '<span class="tab">'. check_plain($link['title']) .'</span>';
    $link['options']['html'] = TRUE;
  }

  if (empty($link['type'])) {
    $true = TRUE;
  }

  return l($link['title'], $link['href'], $link['options']);
}

I really need to get this working. Also tried setting the main theme as the default but still have the problem.

Is there a way around this?

Thanks
J

tamerzg’s picture

Assigned: Unassigned » tamerzg

I will take a look into this. Seems like a major bug.

JosephH’s picture

I also have this problem, have a different theme as my admin theme and it messes it all up, giving lots of the same error and the menu dissappears!

canen’s picture

The problem lies in the variable_set('oldtheme_menu_item_link', $theme_overwrite); call. It's unreliable. To fix this I generated the $theme_overwrite variable myself. It works for themes that have one base (tested with Zen) and themes that don't use a base. I am not sure how well it works with themes whose base goes more than one up. Replace the start of the special_menu_itemsoverwrite_menu_item_link function with the following and it should work.

function special_menu_itemsoverwrite_menu_item_link($link) {
  global $theme, $base_theme_info;
  $base_theme_info = array_reverse($base_theme_info);

  if (function_exists($theme . '_menu_item_link')) {
    $theme_overwrite = $theme . '_menu_item_link';
  }
  else if ($base_theme_info) {
    foreach ($base_theme_info as $base) {
      $name = $base->name;
      if (function_exists($name . '_menu_item_link')) {
        $theme_overwrite = $name . '_menu_item_link';
        break;
      }
    }
  }
  else {
    $theme_overwrite = 'theme_menu_item_link';
  }
  //....... rest of function 
tamerzg’s picture

Thank you Canen. I will review your patch and post it with next release.

JosephH’s picture

Fixed it for me!

BrandTim’s picture

Fixed it for me as well. Thanks canen.

BrandTim

tamerzg’s picture

Status: Active » Fixed

Will be added with next release.

allella’s picture

A patch based on canen's fix in #5.

Status: Fixed » Closed (fixed)

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

zarudnyi’s picture

Version: 6.x-1.3 » 6.x-1.4
Status: Closed (fixed) » Active

Hi,
sorry for disturb but I can't start it to work on right way.
Patch from comment #10 don't solved issue.
call_user_func() [<a href='function.call-user-func'>function.call-user-func</a>]: First argument is expected to be a valid callback in /path/to/site/root/sites/all/modules/special_menu_items/special_menu_items.module on line 118.
Thanks for any help.

aleksey.tk’s picture

For me patch from comment #10 solve the issue, please commit it (or wait until someone else confirms the patch working, just to be sure)

davepoon’s picture

The patch can not solve the issue for me.
I created a zen subtheme for the website, and use admin theme for the admin theme.
This is my error,
warning: call_user_func(zen_menu_item_link) [function.call-user-func]: First argument is expected to be a valid callback in /Applications/MAMP/htdocs/example/sites/all/modules/contrib/special_menu_items/special_menu_items.module on line 125.

bserem’s picture

I have the same problem, zen with Garland as admin theme

if I chose zen as admin theme everything is ok

theunraveler’s picture

+1

PMatwyuk’s picture

Getting the same error as #14.

I have a site that uses the page theme module and all pages I use the Inove theme I get the error. Please help/advise. I'm using version 6.x-1.5 of this module.

yul63’s picture

Thank you.

Just to be more specific, in special_menu_items.module replace :

function special_menu_itemsoverwrite_menu_item_link($link) {   
  $theme_overwrite=variable_get('oldtheme_menu_item_link',null); 

by the code at # 5.

tdous’s picture

Version: 6.x-1.4 » 6.x-1.5

Will that patch be implemented? Still missing as of 1.5.

DarrellDuane’s picture

Status: Active » Needs review

Thanks for this patch, it worked well for me. I recommend it be implemented.

PMatwyuk’s picture

The patch worked perfectly for me.

kreynen’s picture

+1 on this patch

mrfelton’s picture

Following the instructions in #18 worked for me.

khaled.zaidan’s picture

Hi guys,

Looks like the patch solved the issue. I will review it soon, and add it in the next release.

Best regards,
Khaled Zaidan

mariano.barcia’s picture

I can report the patch wasn't working with older versions of the rubik&tao themes (for admin module 2.0-beta2), but now with the latest versions it's working properly. Thanks!

rocketfuel’s picture

I have had the same problem, and none of these fixes helped - I have sub-sub-themes of Zen, which may be why. After tearing my hair out, I finally found an easy workaround, the Menu Firstchild module http://drupal.org/project/menu_firstchild - it does the same job but doesn't cause the problems. You just change the URL of the menu item to instead of .

*Please note that this module doesn't provide the seperator.

This is my first post on a forum like this so apologies if it is in the wrong place. In my defence, I think that the info I supplied will be helpful to Special Menu Items because perhaps the Zen sub-sub-theme thing is a clue that might help solve the problem. Also, it seemed to get worse when I turned on caching, i.e. the site broke when i went live :P

gmclelland’s picture

Patch #10 worked for me.

mariano.barcia’s picture

Status: Needs review » Needs work

Hi there. Well, it's not working (perhaps the cache tricked me the last time I reported success with the patch).

Using admin module, with rubik/tao as the administration theme, and acquia_marina (latest version of everything), I get error on line 142 of the module.

Sorry I cannot be of help, just reporting the problem as much as I can. BTW, this has become a real "show stopper" for several of our projects :-/

I found a workaround though. I tried setting the admin theme as the system default, while leaving only acquia_marina active (the site's theme), cleared the menu cache, and now the error is gone. I prefer having to use the acquia marina as the admin's theme, than not having the nolink menu items. Any ideas?

Thanks.

bleen’s picture

subscribing

mshepherd’s picture

patch at #10 worked for me too.

shawngo’s picture

I ran into the same error as #28 with the Tao theme. The patch in #10 assumes it will find the function THEMENAME_menu_item_link in the foreach loop on (or around) line 97 in special_menu_items.module which Rubik (and probably others) do not.

I rick-rolled the patch (did I say that correctly?) checking for an existing function within $theme_overwrite.

mariano.barcia’s picture

Status: Needs work » Reviewed & tested by the community

It works in my installation now, thanks shawngo! Please commit.

cookiesunshinex’s picture

I'm getting this error too (using Zen as user them, and Garland as the admin theme).

I'm using the latest release, is this patch rolled into the dev?

Volx’s picture

I had the same problem with a subtheme of the zen theme, patch #31 fixed it for me. Thanks!

cookiesunshinex’s picture

#31 works for me too.

I'm using Zen and a custom Zen sub-theme for my main content.
I'm also using Tao and Rubik for administration theme.

Thanks!!!

scottrouse’s picture

Patch in #31 solved my problem. I was getting errors with Root Candy.

Edit: I marked a similar issue on the Root Candy queue (http://drupal.org/node/762908) as a duplicate of this issue.

Daniel Norton’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +themes
FileSize
1.14 KB

The patch at #31 doesn’t seem to match the current version. This one does.

Danny_Joris’s picture

#37 Thanks for the patch. I manually applied it. It looks good. The nature of the error messages is that it seemed to appear quite randomly and would disappear after a refresh, so it is difficult to tell if it actually worked. For now everything looks good. Will let you know when I encounter the error messages again.

I have the same setup as #35: Zen + Zen subtheme as main theme and Tao & Rubik as administration theme.

Thanks again!
Danny

mherchel’s picture

Manually applying the patch worked for me also. I use Rootcandy Dark as my admin theme. Thanks,

timofey’s picture

For those of you who don't know how to apply patches, open special_menu_items.module,

Replace:

function special_menu_itemsoverwrite_menu_item_link($link) {   
  $theme_overwrite=variable_get('oldtheme_menu_item_link',null);

With:

function special_menu_itemsoverwrite_menu_item_link($link) {
  global $theme, $base_theme_info;
  $base_theme_info = array_reverse($base_theme_info);

  if (function_exists($theme . '_menu_item_link')) {
    $theme_overwrite = $theme . '_menu_item_link';
  }
  else if ($base_theme_info) {
    foreach ($base_theme_info as $base) {
      $name = $base->name;
      if (function_exists($name . '_menu_item_link')) {
        $theme_overwrite = $name . '_menu_item_link';
        break;
      }
    }
  }
  if ($theme_overwrite == '' || !function_exists($theme_overwrite)) {
    $theme_overwrite = 'theme_menu_item_link';
  }

This is based on a patch from Post #37. It works with 6.x-1.5

mrfelton’s picture

Patch updated against HEAD

gmclelland’s picture

#41 worked for me

emmajane’s picture

Status: Needs review » Reviewed & tested by the community

Patch at #41 also works for me.

scottiw2000’s picture

Patch at #41 worked for me too, though I'm not sure what caused the error since I wasn't using multiple themes.

JamesAn’s picture

+1 for the patch in #41. Worked for me.

TuFrac’s picture

What I said in # 18 worked perfect for me rootcandy taken for administration and a theme created by me for the site.

alex.skrypnyk’s picture

Can we please have patch in #41 added to HEAD?

axe312’s picture

#41 worked finde for me!

(Theme: Zen-Subtheme, Admin-Theme: Rootcandy )

PLEASE add it to the head!

Danny_Joris’s picture

I must say I tried this patch in another website and the error messages disappeared, but also all my menu links disappeared (except for the special menu items), so I had to revert it...

I have this snippet in my zen 1.0 subtheme template.php

 <?php
/**
* Implementation of theme_menu_item_link().
*
* Integrates Menu Class
*/
function phptemplate_menu_item_link($link) {
  if (function_exists('menuclass_to_link')) {
    menuclass_to_link($link);
  }
  return theme_menu_item_link($link);
}
?> 

Edit: I replaced "phptemplate" with my theme name and added the patch again. It seems to work without breaking the menu links for now. That's a snippet from the Menu Class module, btw (which is now considered obsolete).

...So yeah, #41 works for me too! :)

pacome’s picture

#41 Worked for me too
Thank you !

Maciej Lukianski’s picture

#41 works for me as well. Can this be comitted?

joelstein’s picture

#41 works for me.

lourenzo’s picture

I had a similar problem, using a custom zen-based frontend theme and rubik as admin theme.

Sometimes, the frontend menu was broken, sometimes the admin tabs would be gone.
Both problems could be temporarily solved by clearing the cache, but I had to put an end in those shameful broken screens.

Debugging the system, I discovered a bug: special menu items module caches only one preprocess function globally.
I just thought of changing the variable from string to an keyed array, in which keys are the theme_key global, that represents the
active theme by the time the hook for registry alteration is called.

That solves the problem for good, adding virtually no overhead and only 4 more lines of code

function special_menu_items_theme_registry_alter(&$theme_registry) {
  global $theme_key;
  $theme_overwrite = variable_get('oldtheme_menu_item_link', array());
  $theme_overwrite[$theme_key] = $theme_registry['menu_item_link']['function'];
  // [...]
}
function special_menu_itemsoverwrite_menu_item_link($link) {
  global $theme_key;
  $theme_overwrite=variable_get('oldtheme_menu_item_link', array());
  $theme_overwrite=$theme_overwrite[$theme_key];
  // [...]
lourenzo’s picture

Status: Reviewed & tested by the community » Needs review
jimmynash’s picture

Ran into this issue today.

I applied the patch in #53 but after clearing the cache had menu links that said "Array" in the regular navigation menu in Garland.
I also received several other warnings on the page. Apologies, I did not keep them.

Edit:
After applying the patch in #53 I saw the same warnings as well as:
warning: Illegal offset type in isset or empty in /var/www/html/mysite/www/includes/common.inc on line 915.

I rolled that one off and applied the one in #41 and it fixed the issue I had of valid callback warnings.

Using Zen subtheme for main template, Garland as the admin template.

Versions: Drupal 6.22
Zen 6.x-2.1
Special menu Items 6.x-1.5

lourenzo’s picture

@jimmynash, I forgot to mention that the variable type is changed to array, so it needs to be deleted before applying the patch.
And you need to rebuild the theme cache too.

So, the original funcion names are saved on rebuild and loaded according to the current $theme_key value.
Talking about performance, I still thinking the module overhead should be concentrated at the theme registry rebuild, and not at the rendering function.

joep.hendrix’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm that patch #53 works.
Upgrading would mean to first unintstall the module in order to delete the variable "oldtheme_menu_item_link".
Or:

delete from variable where name='oldtheme_menu_item_link';
andremolnar’s picture

FileSize
9.8 KB

Here is a patch against the 1.5 tag for people applying patches during drush make. - see @patcon http://drupal.org/node/1054616#comment-4152234

andremolnar’s picture

FileSize
1.36 KB

Ooops that file didn't work -

gagarine’s picture

I don't have the time to read all the issue... But I post a patch https://github.com/webflo/special_menu_items/pull/3 for D7 than should probably solve that.

btopro’s picture

sub

d3str0y’s picture

I've got the same problem.

call_user_func(rootcandy_menu_item_link) [function.call-user-func]: First argument is expected to be a valid callback in /path/to/site/sites/all/modules/special_menu_items/special_menu_items.module on line 125.

B-Prod’s picture

Version: 6.x-1.5 » 6.x-1.x-dev
FileSize
2.46 KB

This patch is a fork from #59 but removes the deprecated variable ''oldtheme_menu_item_link" in an update function inside the .install file, then rebuild the theme registry.

gagarine’s picture

Status: Reviewed & tested by the community » Patch (to be ported)
gagarine’s picture

Status: Patch (to be ported) » Fixed

Committed in 6.x-1.x-dev. I didn't try on 7.x if we also have this issue fee free to reopen in this case.

http://drupalcode.org/project/special_menu_items.git/commit/7008a3a

doublejosh’s picture

Patiently awaiting release :)

gagarine’s picture

I will love if instead you try the dev release to check if it works :). The -dev is ready for a release I just wait than some peoples try it... (backup first so it's 100% safe)

If nobody try, is not going to have a new release because I personally don't use the D6 version.

xeraseth’s picture

I was having the same issue as 14 and 62, switching to the lastest dev version has fixed the issue.

EDIT: I am using a custom Zen subtheme on Drupal 6.22

gagarine’s picture

Assigned: tamerzg » gagarine

thanks xeraseth to try the dev. I'm going to release a new stable version when I catch some times.

EDIT: done

Status: Fixed » Closed (fixed)

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

ClaireC’s picture

Version: 6.x-1.x-dev » 6.x-1.5
Status: Closed (fixed) » Reviewed & tested by the community

#31 Thank you for your patch.

bleen’s picture

Version: 6.x-1.5 » 6.x-1.x-dev
Status: Reviewed & tested by the community » Closed (fixed)

please do not reopen this issue unless you feel the bug is not yet completely fixed