When adding a node to a section I'd like pathauto to use the URL of the parent menu item rather than it's menu path. Would it be within the scope of menu_node_edit to make such a token available or is should this be posted elsewhere?

Comments

agentrickard’s picture

This is the place. We actually need this feature, too. You would have to lookup the following:

{menu_links}.link_path == {url_alias}.src

Grab {url_alias}.dest and use that as the token value. We also need to account for a NULL return.

agentrickard’s picture

Status: Active » Needs review
StatusFileSize
new2.19 KB

Here's a patch. If no match is found, we return the string 'content' as the path, since we can't really have an empty token.

agentrickard’s picture

StatusFileSize
new2.06 KB

Better patch.

agentrickard’s picture

StatusFileSize
new2.06 KB

Fixes stupid logic error.

roboneale’s picture

That's working for me. Thanks.

agentrickard’s picture

Ideally, I think that 'content' string should be configurable.

roboneale’s picture

If I use the -raw token within a pathauto replacement pattern the forward slashes for that token don't appear in the resulting URL. The non-raw token does what I want but I'm a little cautious to use it as pathauto gives me the following warning.

You are using the token [menu-parent-path-alias] which has a -raw companion available [menu-parent-path-alias-raw]. For Pathauto patterns you should use the -raw version of tokens unless you really know what you are doing. See the Pathauto help for more details.

In this case I couldn't comfortably say I "really know what I'm doing".

agentrickard’s picture

The non -raw should be fine. I really don't understand that part of PathAuto/Token, and this it is a horrible UI failure. The -raw token is not well-documented, but here, you should be fine with the plain-text version.

agentrickard’s picture

StatusFileSize
new2.06 KB

Hah. -raw is worthless. Pathauto strips the / from anything labeled '-raw'. It has to be -path.

This is a WORTHLESS UNDOCUMENTED "FEATURE" of PathAuto. To wit:

function pathauto_clean_token_values($full) {
  foreach ($full->values as $key => $value) {
    // If it's a "path" or "url friendly" token don't remove the "/" character
    if (drupal_substr($full->tokens[$key], -4, 4) === 'path' || drupal_substr($full->tokens[$key], -8, 8) === 'path-raw' || drupal_substr($full->tokens[$key], -5, 5) === 'alias') {
      $full->values[$key] = pathauto_cleanstring($value, FALSE);
    }
    else {
      $full->values[$key] = pathauto_cleanstring($value);
    }
  }
  return $full->values;
}
agentrickard’s picture

Status: Needs review » Fixed

Committed to HEAD.

Status: Fixed » Closed (fixed)

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