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].

Files: 
CommentFileSizeAuthor
#27 1266928-parents-array.patch9.75 KBDave Reid
PASSED: [[SimpleTest]]: [MySQL] 314 pass(es).
[ View ]
#19 1266928-d7-3.patch4.48 KBredndahead
PASSED: [[SimpleTest]]: [MySQL] 296 pass(es).
[ View ]
#19 1266928-d7-4.patch4.96 KBredndahead
PASSED: [[SimpleTest]]: [MySQL] 296 pass(es).
[ View ]
#18 1266928-d7-2.patch6.82 KBredndahead
PASSED: [[SimpleTest]]: [MySQL] 296 pass(es).
[ View ]
#17 1266928-d7-1.patch6.34 KBredndahead
PASSED: [[SimpleTest]]: [MySQL] 296 pass(es).
[ View ]
#15 1266928-parents-array.patch3.23 KBsense-design
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1266928-parents-array_0.patch. See the log in the details link for more information.
[ View ]
#14 1266928-parents-array.patch6.79 KBsense-design
PASSED: [[SimpleTest]]: [MySQL] 296 pass(es).
[ View ]
#4 1266928-parents-array.patch6.79 KBDave Reid
PASSED: [[SimpleTest]]: [MySQL] 296 pass(es).
[ View ]
#3 1266928-parents-array.patch0 bytesDave Reid
PASSED: [[SimpleTest]]: [MySQL] 296 pass(es).
[ View ]

Comments

+1 and subscribing

subscribing

Status:Active» Needs work
StatusFileSize
new0 bytes
PASSED: [[SimpleTest]]: [MySQL] 296 pass(es).
[ View ]

Initial patch.

Todo:
- Documentation
- Tests

StatusFileSize
new6.79 KB
PASSED: [[SimpleTest]]: [MySQL] 296 pass(es).
[ View ]

subscribe

subscribe

subscribe

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

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.

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.

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

subscribe

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).

StatusFileSize
new6.79 KB
PASSED: [[SimpleTest]]: [MySQL] 296 pass(es).
[ View ]

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

StatusFileSize
new3.23 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1266928-parents-array_0.patch. See the log in the details link for more information.
[ View ]

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.

@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.

Status:Needs work» Needs review
StatusFileSize
new6.34 KB
PASSED: [[SimpleTest]]: [MySQL] 296 pass(es).
[ View ]

Here is a re-roll of #4

StatusFileSize
new6.82 KB
PASSED: [[SimpleTest]]: [MySQL] 296 pass(es).
[ View ]

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

StatusFileSize
new4.96 KB
PASSED: [[SimpleTest]]: [MySQL] 296 pass(es).
[ View ]
new4.48 KB
PASSED: [[SimpleTest]]: [MySQL] 296 pass(es).
[ View ]

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

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

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

Issue tags:+Needs tests

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

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?

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.

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?

Adding blocker tag.

Status:Needs work» Needs review
Issue tags:-Needs tests
StatusFileSize
new9.75 KB
PASSED: [[SimpleTest]]: [MySQL] 314 pass(es).
[ View ]

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.

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

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

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.

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).

Status:Closed (fixed)» Needs work

Status:Needs work» Closed (fixed)