I am debating creating an array token type in Token module which could then be extended by Pathauto to help provide the 'fake' URLs like menupath and catpath that we're currently missing from D6.

See #860082: BIKESHED: Token for a term or menu item's entire tree/hierarchy - I'm making this a major issue before 7.0 release of Pathauto and Token modules.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Title: Provide an [array:pathauto] token » Provide an [array:join-path] token
Dave Reid’s picture

Dave Reid’s picture

Status: Active » Needs review
FileSize
4.67 KB

Patch attached for review.

Dave Reid’s picture

Status: Needs review » Needs work
Issue tags: -D7 stable release blocker

The last submitted patch, 1046972-pathauto-array-join-path-token.patch, failed testing.

Dave Reid’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
Issue tags: +D7 stable release blocker

The last submitted patch, 1046972-pathauto-array-join-path-token.patch, failed testing.

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
4.69 KB
Dave Reid’s picture

Status: Needs review » Reviewed & tested by the community

Currently the name of this token is [array:join-path]. What it does is take all the values in an array token, apply Pathauto clean-stringing to each value, and then joins the values together into a string with the '/' character. For example, given a [node:menu-link:parents:join-path] token and the node's menu link has the hierarchy of 'Root menu link' and then 'Parent menu link', the token would output as 'root-menu-link/parent-menu-link'.

Anyone have any other opinions on the name of this token (join-path)?

realityloop’s picture

Status: Reviewed & tested by the community » Needs work

I'm wondering if joined-path my provide a better tense for this?

"what will this token return to me?" it returns a joined path..

"joined" alone would make sense to me too..

jenna.tollerson’s picture

I like joined or joined-path. It is a little clearer, differentiates it from join:?

mallezie’s picture

I also like joined. It's more clear than join.

redndahead’s picture

Status: Needs work » Needs review
FileSize
4.7 KB

This is a patch with the joined-path version

realityloop’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me

acrollet’s picture

patch in #13 works for me as well.

redndahead’s picture

SilviuChingaru’s picture

#13 is working like a charm for me too... Thank you!

redndahead’s picture

FYI Dave Reid is leaning towards using the patch in #8. That patch works also. We just need to be patient for dave to get his focus back to this module only 2645 modules to get past first. ;)

AQ808’s picture

Can we just clone him instead?

SilviuChingaru’s picture

patch #8 is working in more complex enviroment with taxonomy refs fields with multiple values. Waiting to see patch in dev at least.

RedTop’s picture

I've applied the patch in #8 but have no clue how to use it. Could someone tell me what token they used to get the menu path output?

redndahead’s picture

[node:menu-link:parents:join-path]/[node:menu-link:title]
RedTop’s picture

Checked the result of the patch a number of times but cannot find anything wrong with it. Still getting an error though. :/

using the following invalid tokens: [node:menu-link:parent:join-path].

redndahead’s picture

parents not parent

RedTop’s picture

Sorry, posted the wrong attempt, tried that after parents did not work either.

Are you using the patch in #8 or #13?

edit: tried both patches, same result.

redndahead’s picture

I'm using #8 are you using the latest dev release also?

RedTop’s picture

I wasn't, now I am... didn't solve the issue though. I'll muddle through and may have to wait till a proper release.

Edit: solved, needed to update token to latest dev as well. Sorry for wasting your time! Thanks. :)

Dave Reid’s picture

Finally getting back to this. Everyone else pretty much prefers 'joined-path' even though Token module uses [array:join:join characters]?

realityloop’s picture

I personally think that joined-path is more indicative of what gets returned.. but if you prefer join-path I'm more than happy to accept it, your the maintainer after all :)

I'd prefer to see this get committed rather than haggle over tense.

Dave Reid’s picture

Status: Reviewed & tested by the community » Fixed

Committed #8 with http://drupalcode.org/project/pathauto.git/commit/e09ab90. Thanks all for being patient with me.

drupalinside’s picture

#13 works for me only for nodes using [node:terms:join-path]

but i'd like to use also for taxonomy hierarchy, using [term:terms:join-path] nothing happens, so i tried to use [term:name] to check functionality and it works.

Where i'm failing?

there's something like to use something like " [terms:name:join-path]

thanks in advance

Dave Reid’s picture

@drupalinside: [term:parents:join-path]

drupalinside’s picture

thanks Dave, but i cant see "parentS" in token list, if i insert it manually got error message, tried stble version , patched stable version and dev version, there's something wrong i can't understand

regards

Dave Reid’s picture

Make sure you are using Token 7.x-1.x-dev (the latest one) and clear your site's caches by running update.php quick.

drupalinside’s picture

Thank you Dave, got it
sorry for wasting your time

regards

ANDiTKO’s picture

Status: Fixed » Needs review
Issue tags: -D7 stable release blocker

Status: Needs review » Needs work
Issue tags: +D7 stable release blocker

The last submitted patch, 1046972-joined_path_token-d7-1.patch, failed testing.

Dave Reid’s picture

Status: Needs work » Fixed
ANDiTKO’s picture

Status: Fixed » Needs review
ANDiTKO’s picture

I cant apply any patch. I tried #8 and #13 but it wont do it.
Is this already ported to the latest pathauto 7.x-1.x-dev version?

Because i downloaded the latest 7.x-1.x-dev and i cant get the token to work.

MustangGB’s picture

Dave marked this as fixed so presumably either grab a git checkout or wait for it to filter through to dev release

acrollet’s picture

Status: Needs review » Closed (cannot reproduce)

This issue was committed here: http://drupalcode.org/project/pathauto.git/commit/e09ab90

The latest dev release contains this code.

acrollet’s picture

Status: Closed (cannot reproduce) » Closed (fixed)

whoops, wrong status.

Drupa1ish’s picture

Issue summary: View changes

This token is available only for taxonomy terms attached to node, with a single value. Is possible to provide also for taxonomy terms with unlimited cardinality? Thanks

jelo’s picture

This token is awesome. May I suggest a modification which I believe would be very simple and very useful. Right now the available tokens only allow to use the first parent, the last or all of them joined. However, it is not easily possible to create a structure to have /first-level/second-level/node-title or /first-level/second-level/third-level/node-title.

I am proposing to add a depth limitation to this existing token, e.g.
[node:menu-link:parents:join-path/depth]

I am not sure how to pass the depth into the token, but I think all it would need in the logic to create the token is a line like this before
$replacements[$original] = implode('/', $values);

if (isset($depth) && int($depth)) array_slice($values, 0, $depth);

What do you think?

Dave Reid’s picture

@jelo I would recommend creating a custom token for that. I don't really have much interest in supporting too many advanced use cases. We're just trying to provide for the majority use case that needs tokens here in Token module, so I hope you will understand.

jelo’s picture

@Dave. Sure, I understand. I will check how to create my custom token for this.

Having said this, I would like to point out that my suggestion would eliminate a couple of tokens with a single one, i.e. it could cover already defined use cases plus additional ones all with less code.
[node:menu-link:parents:join-path/depth] could replace all of these tokens:

[node:menu-link:parents:join-path] => stays the same with no depth provided
[node:menu-link:parents:first] => [node:menu-link:parents:join-path/1]
[node:menu-link:parents:last] => [node:menu-link:parents:join-path/1:reversed]

While searching for a solution for "my" use case I came across a number of forum questions (e.g. on stackexchange, d.o etc.) for this particular use case, i.e. this might actually be a very common use case to create URL alias patterns like this /first-level/second-level/node-title

Cheers, J.

jelo’s picture

FileSize
1.15 KB