0

I can't get any node:menu-based tokens to work in my Pathauto replacement patterns. Other tokens, such as [current-user:name] or [node:language], work fine. But the token I am trying to use, a menu-based token, specifically [node:menu-link:parents:join:/] does not. I've tried a slew of the node:menu-link tokens, such as [node:menu-link:parent:url:path], and they're all being skipped.

When I bulk delete all Content aliases, then bulk update them, I do not get any error messages. The resulting aliases from my pattern [node:menu-link:parents:join:/]/[node:title] just ends up being the node title. git status

I've been banging my head against this for days, and in trying to fix it have:

  • installed Token Tweaks and set the depth to 2
  • run drush @test ev "token_clear_cache(); incessantly
  • disabled Menu Firstchild, then when that didn't help...
  • updated Menu Firstchild to the dev version and applied this patch
  • applied this Token patch
  • applied this core (!) patch

Now I'm running:

  • Pathauto 7.x-1.2+21-dev
  • Token 7.x-1.5+4-dev
  • Token Tweaks 7.x-1.x-dev
  • Menu Firstchild 7.x-1.1+1-dev

An additional detail: Going to node/[nid]/devel/token for any given page hangs for a while, then displays a blank screen. It produces three errors like this:

Notice: Undefined property: stdClass::$field_studio_location in addressfield_tokens() (line 219 of /var/www/html/test/sites/all/modules/contrib/addressfield/addressfield.tokens.inc).

This doesn't seem particularly serious, but maybe relevant.

Any ideas? Even pointers on how to debug would be great.

0

FWIW, this was actually caused by the menu not being selected in the Menu Settings of this particular content type. Thanks for the help!

1

Just encountered that, after a full debug, it seems that menu_tokens() is not called at all.

  // There is a huge bug with menu tokens not being detected, to fix that, load
  // token include file and force repicking the menu_tokens() function as
  // implementation of hook_tokens()
  module_load_include('inc', 'token', 'token.tokens');
  module_implements('tokens', FALSE, TRUE);

That crappy hack fixed my problem but Why... just WHY ?

So yeah, after a deeper investigation, in module_implements():

  $include_file = isset($hook_info[$hook]['group']) && module_load_include('inc', $module, $module . '.' . $hook_info[$hook]['group']);
  // Since module_hook() may needlessly try to load the include file again,
  // function_exists() is used directly here.
  if (function_exists($module . '_' . $hook)) {
    $implementations[$hook][$module] = $include_file ? $hook_info[$hook]['group'] : FALSE;
  }

Okay, so the only thing that is preventing menu from being picked is the sorting:

  • if menu is processed before token in this module_implements(), the menu.tokens.inc include file will not be picked as it doesn't exist
  • if token is before menu, the token.tokens.inc thus menu_tokens() function will be discovered and picked up after

So if you don't want any code, just alter the weight of token and menu so that menu's is higher than token's.

But NO, there is a token_module_implements_alter() that just does that, but it is not called, and that is the thing I couldn't figure out. So the final hack was:

  // Rebuild implementation cache
  cache_set('module_implements', array(), 'cache_bootstrap');
  cache_clear_all('hook_info', 'cache_bootstrap');
  • Thanks for the awesome & thorough debugging — I'll have time to implement/test next week. – Beatrice Oct 10 '14 at 17:38

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.