The bookpath token is currently built from the titles of the parent nodes in the book.
With pathauto, which is likely the most frequent use of this token, if the path to one (or more) of the parent nodes has been manually set, this means the book path components won't match a working path hierarchy even if the number of components is the renamed path is correct: backtracking to home by removing the last path component will leave the user at an invalid alias for that level.
However, if the aliases to each level in the book hierarchy were used to build the bookpath, this problem would not occur, as long as the forced aliases maintain the path logic (number of components, hierarchy consistency). Although "bookpath" is a builtin token of token module, I'm not sure whether this is really a pathauto or token issue.
Comment | File | Size | Author |
---|---|---|---|
#1 | token_bookurl.patch | 5.47 KB | nirbhasa |
Comments
Comment #1
nirbhasa CreditAttribution: nirbhasa commentedI am attaching a patch that adds 2 new tokens [bookurl] and [bookurl-raw] that generate the combined url path of all parents in the node's book hierarchy.
In order to do this, I changed the _menu_titles function to a more general _menu_info, allowing me to use it to return both the titles and the url aliases of the parents in the hierarchy.
Along the way 2 issues were fixed, that also affected the existing [bookpath] and [bookpath-raw] tokens
1) If the top book is the site frontpage, we shouldn't put its url/title in the trail.
2) For book paths, we don't include the current node's title/path the array in the trail. However _menu_info (formerly _menu_titles) function doesn't return current nodes title/path if node is unpublished, so in that case there is no need to remove anything.
However I have one last problem: the function book_token_values returns the proper token (pathA/pathB/pathC, say), but somewhere later, all the slashes are taken out and I am left with pathApathBpathC as my alias. This doesnt happen with the [bookpath] and [bookpath-raw] tokens, and I'm a little mystified as to what's so different about my tokens. If someone could help me with this, that would be fantastic!
Comment #2
BarisW CreditAttribution: BarisW commentedI used another approach to get this working, using my own token function for this.
It is important that the token identifier (bookurl-path) ends with path. This will make sure the slashes aren't filtered out.
Comment #3
lion123 CreditAttribution: lion123 commentedHi,
I really need this functionality. Where should I insert this code?
Thank you in advance
Comment #4
nirbhasa CreditAttribution: nirbhasa commentedFor the approach in 1) you can apply the patch (there's a how to here.... For the approach in 2) you can put the code in a module (put the code in a .module file, write a .info file and youre done. For more on writing modules see http://drupal.org/node/206753)
Comment #5
lion123 CreditAttribution: lion123 commentedThank you for the reply. I'll try it and let you know about the results :)
Comment #6
Dave ReidNeeds tests and more reviews to be committed.
Comment #7
skaught_ CreditAttribution: skaught_ commentedre:#2 :: BarisW
perfect my friend....i was looking to just this fix.
Comment #8
anarcat CreditAttribution: anarcat commentedsubscribing. the custom module approach is cool, but it would be nice to merge this in the module directly... seems simple enough.
@Dave Reid - when you speak of "tests", do you mean unit tests? Otherwise this issue should be needs review...
Comment #9
ergonlogic@BarisW: Thank you, exactly what we were looking for.
We're glad to report that the token implementation in comment #2, is currently live, in production, and working worderfully over at http://community.aegirproject.org/handbook.
Comment #10
jiv_e CreditAttribution: jiv_e at LilDrop Consulting commentedI believe #2 solves the issue. Please reopen if you feel this is not the case!