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.

CommentFileSizeAuthor
#1 token_bookurl.patch5.47 KBnirbhasa
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nirbhasa’s picture

Title: Bookpath does not necessarily reflect the actual book path » Additional tokens for book url path
Version: 6.x-1.11 » 6.x-1.x-dev
Category: bug » task
Status: Active » Needs review
FileSize
5.47 KB

I 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!

BarisW’s picture

I used another approach to get this working, using my own token function for this.

function MODULENAME_token_values($type, $object = NULL, $options = array()) {
  if ($type == 'node') {
    $node = $object;
    $tokens['bookurl-path'] = '';
	
    if (!empty($node->book['plid'])) {
      $parent = book_link_load($node->book['plid']);
      $tokens['bookurl-path'] = drupal_lookup_path('alias', $parent['href']);
    }
    return $tokens;
  }
}

function MODULENAME_token_list($type = 'all') {
  if ($type == 'node' || $type == 'all') {
    $tokens['book']['bookurl-path']      = t("The full url of the parent node.");
    return $tokens;
  }
}

It is important that the token identifier (bookurl-path) ends with path. This will make sure the slashes aren't filtered out.

lion123’s picture

Hi,

I really need this functionality. Where should I insert this code?

Thank you in advance

nirbhasa’s picture

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

lion123’s picture

Thank you for the reply. I'll try it and let you know about the results :)

Dave Reid’s picture

Status: Needs review » Needs work

Needs tests and more reviews to be committed.

skaught_’s picture

re:#2 :: BarisW
perfect my friend....i was looking to just this fix.

anarcat’s picture

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

ergonlogic’s picture

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

jiv_e’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

I believe #2 solves the issue. Please reopen if you feel this is not the case!