Extending from #860082: BIKESHED: Token for a term or menu item's entire tree/hierarchy we should provide [term:parents] and [menu-link:parents] tokens which are an array of the parents of the respective term or menu link starting at the root as the first element value, and the immediate parent as the last array value (e.g. array('Root', 'First sub-term', 'Term parent')). Together with an [array:pathauto] token that joins the array values with '/' after applying its string cleaning to each value, we can now fully implement our [termpath], [catpath] and [menupath] tokens as [term:parents:pathauto].

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MustangGB’s picture

+1 and subscribing

rp7’s picture

subscribing

Dave Reid’s picture

Status: Active » Needs work
FileSize
0 bytes

Initial patch.

Todo:
- Documentation
- Tests

Dave Reid’s picture

FileSize
6.79 KB
brant’s picture

subscribe

Fabianx’s picture

subscribe

fenstrat’s picture

subscribe

acbramley’s picture

sub. Patch failed on latest dev release, only the info file though.

acbramley’s picture

Tested [node:menu-link:parents:join:?] not too sure where the "join" character is meant to go (I assume it should replace the question mark? If so, it didn't work for me.

acbramley’s picture

Ah I got it [node:menu-link:parents:join:/] gave me an imploded url of parent menu items. I had to change punctuation settings to not remove slashes though, this means that slashes in node titles wouldn't be removed though but this should be fine.

acrollet’s picture

patch in #4 applies cleanly to latest 7.x-1.x, taxonomy parents token works great, thanks much!

abaddon’s picture

subscribe

dtrdewaele’s picture

On what version do you apply the patch? Tried it on beta6 and dev release but both give errors. Tokens are available, but as soon as I bulk update my aliases, I get errors (deleted aliases first).

sense-design’s picture

FileSize
6.79 KB

Please apply #4 to your token module, then take this patch to patch the "token.tokens.inc", continue with #10 after that.

sense-design’s picture

FileSize
3.23 KB

Please ignore #14

Please apply #4 to your token module, then take this patch to patch the "token.tokens.inc", continue with #10 after that. This is the correct patch.

wojtha’s picture

@sense-design I tried the patch from #15, but when I tried apply it I got:

> git apply 1266928-parents-array_0.patch.1
1266928-parents-array_0.patch.1:34: trailing whitespace.
1266928-parents-array_0.patch.1:49: trailing whitespace.
1266928-parents-array_0.patch.1:79: trailing whitespace.
error: token.tokens.inc Locally Modified (Based On LOCAL): No such file or directory

So I applied the patch manually. Now when I look at diff I see the only change:

@@ -414,6 +413,11 @@ function token_tokens($type, $tokens, array $data = array(), array $options = ar
           $type_name = node_type_get_name($node);
           $replacements[$original] = $sanitize ? check_plain($type_name) : $type_name;
           break;
+        case 'parents':
+          if ($parents = token_taxonomy_term_load_all_parents($term->tid)) {
+            $replacements[$original] = token_render_array($parents, $options);
+          }
+          break;
       }
     }

The other hunks from your patch #15 seems to be included in the previous patch #4 by Dave Reid. Is it correct? Or am I missed/overlooked something?

Anyway menu parents token seems to be working as expected.

redndahead’s picture

Status: Needs work » Needs review
FileSize
6.34 KB

Here is a re-roll of #4

redndahead’s picture

FileSize
6.82 KB

This is #15 rerolled and it seems wojtha is right about the only change. @sense-design can you explain why you added that piece?

redndahead’s picture

FileSize
4.96 KB
4.48 KB

Per davereid in irc the token.inc portion shouldn't be there.
#3 is #17 patch without token.inc
#4 is #18 patch without token.inc

Dave Reid’s picture

Yeah the addition in #15 should also be ignored. It will not work.

redndahead’s picture

Looks like it passed. So 1266928-d7-3.patch should be the correct patch to use. Anyone care to RTBC?

Dave Reid’s picture

Issue tags: +Needs tests

We still need additional tests to confirm all these tokens are working as expected and in the correct order.

redndahead’s picture

I'm having a difficult time trying to figure out the tests. Any chance of getting an example of the taxonomy parents test and then I can maybe figure out the menu one from there?

mjcarter’s picture

I just tried this out, parents token showed up in replacement patterns with no problems, but trying to generate aliases I got:

Fatal error: Class 'MenuTokenObject' not found in C:\xampp\htdocs\website\sites\all\modules\token\token.module on line 936

This is using the beta 7 release, should I be using the dev version?

Edit: Tried the dev release:

Fatal error: Class 'MenuTokenObject' not found in C:\xampp\htdocs\website\sites\all\modules\token\token.module on line 936

Line 936 is $cache[$mlid] = array($plid => new MenuTokenObject($parent)) + $cache[$mlid];

I tried both patch d7-3 and d7-4 and get the same error with both.

redndahead’s picture

Status: Needs review » Needs work

It seems the token.inc file that was removed from this patch contained the MenuTokenObject class. @davereid is there another patch somewhere that needs to get pushed forward so token.inc can be added?

Dave Reid’s picture

Adding blocker tag.

Dave Reid’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
9.75 KB

Here is the version without needing the objects which should have been left for #1195874: Need to figure out how to create nested tokens from the array token type and not been merged into this issue. This also includes additional tests to ensure the tokens work properly.

Dave Reid’s picture

Status: Needs review » Fixed

This passed the bot and locally for me, so committed #27 to Git. Thanks all!
http://drupalcode.org/project/token.git/commit/c4e5564

redndahead’s picture

Sorry I didn't get to it in time. Thanks for committing quickly.

Dave Reid’s picture

Title: Add [term:parents] and [menu-link:parents] array tokens (also [comment:parents]?) » Add [term:parents] and [menu-link:parents] array tokens

Status: Fixed » Closed (fixed)

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

tahiticlic’s picture

Hi,

this is quite good, but doesn't mimic completely the behavior of termpath token seen on D6. Especially, there's no more "/" separator between terms, and this "/" is replaced by a "-" : is there a way to avoid this?

I mean, on D6 you were able to mix "-" (in the term) and "/" (between terms).

tahiticlic’s picture

Status: Closed (fixed) » Needs work
Dave Reid’s picture

Status: Needs work » Closed (fixed)