Sorry, this probably isn't a token issue, but I just wanted to log it somewhere quickly. It may actually be a conflict with Revisioning or possibly Workflow, both of which are enabled on this site.

In any case, when creating a new node, [menupath-raw] did not include the title of the newly-created node, and only returned a path to the parent, which meant I ended up with path/to/parent-1 instead of path/to/parent/new-node.

I've been using the custom module described in #519834: A variant of [menupath-raw] which excludes the current node, or a token which provides [title-raw] when [menupath-raw] is empty so that I could have a path based on the title if no menu item was entered. I've modified it as follows to work around this issue, by comparing count($trail_raw) to $menu_link['depth'], which seems to work in my tests thus far.

/**
 * @file
 *   Provides [title-or-menupath-raw] token for pathauto titles.
 */

/**
 * Implementation of hook_token_list().
 */
function pathauto_titletoken_token_list($type = 'all') {
  if ($type == 'node' || $type == 'all') {
    $tokens['node']['title-or-menupath-raw'] = t("A path-auto token returning [menupath-raw] if applicable, and [title-raw] if not.");
    return $tokens;
  }
}

/**
 * Implementation of hook_token_values().
 *
 * Replacement for ['title-or-menupath-raw'], for use with pathauto.
 * The 'path-raw' suffix is important: @see pathauto_clean_token_values().
 * Otherwise the '/'s are stripped from the alias.
 *
 * Code is adapted from node_token_values() in token_node.inc
 */
function pathauto_titletoken_token_values($type, $object = NULL) {
  $values = array();
  if ($type == 'node') {
    $node = $object;
    if (!empty($node->menu['mlid'])) {
      if ($menu_link = menu_link_load($node->menu['mlid'])) {
        $trail_raw = _menu_titles($menu_link, $node->nid);

        // The trail omits the link title for NEW nodes,
        // so add it to maintain consistent behaviour.
        // This issue may possibly be related to the revisioning
        // and/or workflow modules.
        if (count($trail_raw) < $menu_link['depth']) {
          $trail_raw[] = $menu_link['title'];
        }

        $menupath_raw = implode('/', $trail_raw);
      }
    }
    $values['title-or-menupath-raw'] = !empty($menupath_raw) ? $menupath_raw : $node->title;
  }
  return $values;
}

Comments

m4olivei’s picture

I am also having this issue. Mind you I'm trying to accomplish something a little more complex where in hook_nodeapi ($op = presave), I automatically set the menu item and expecting that after Pathauto will pick up and create a path for the new node based on the token [menupath-raw]. Theres no reason I can see that it doesn't and in my limited testing I have found that the procedure works for user 1, but not for other users.

Will post back if I find anything.

m4olivei’s picture

I'm not exactly sure, but I think the problem here may have to do with caching. In order to resolve the [menupath-raw] token, the token module calls menu_tree_all_data() (/token/token_node.inc line 233). The menu_tree_all_data function sometimes gets its data from cache. If data is fetched from cache, then the new menu item created when the node was saved might not be there which would explain why it doesn't get added to the path.

Seems, reasonable to me, although its difficult for me to wade through the menu + cache + pathauto code to figure it out for sure..

Anyone out there that can comment further?

Thanks

m4olivei’s picture

After looking deeper, it doesn't look like caching is the issue at all, but organic groups. What I noticed was that when token module loads the relevant link (token.node.inc line 75), the 'access' key in the $menu_link array is FALSE, which is why its not used when building the path. I traced the reason for that key being set to false down to the organic groups module.

It has something to do with how OG is doing node access. Watch it be something simple like some OG setting I'm missing or something like that.

Is anyone else with this issue also using Organic Groups?

Thanks,
~Matt

kr0l’s picture

I'm experiancing the exact same thing, using OG..
I'm not sure how to solve this,

When the same user updates the node the menulink is applied to the path..

Any one patched this or have a workarround?

Dave Reid’s picture

Status: Active » Closed (duplicate)