provide [bookpathalias] token
two2the8 - May 16, 2007 - 00:44
| Project: | Pathauto |
| Version: | 5.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | greggles |
| Status: | closed |
Description
Hey, great module!
I was using pathauto today with some books on my site, and I noticed that [bookpath] builds up book page urls using the *title* of the pages in a book, rather than by using their *paths* (or aliases, or whatever).
For example, I have a top-level book living at 2007/new-stuff that is called 'new stuff'. When pathauto creates aliases for child pages in this book using bookpath as a placeholder, it builds them like this: /new-stuff/whatever instead of like this: /2007/new-stuff/whatever. The latter was what I expected, and what would be ideal, IMHO.

#1
The current behavior is the intended behavior so I'm changing the title, category, and version to reflect your desired behavior. The behavior you see should be in a [bookpath-alias] token much like we have the [catalias] token.
I don't see a whole lot of value in this and it requires an extra DB lookup so I'm somewhat concerned about the performance so I'm not going to work on it.
But it should be a fairly simple patch and I invite someone else to contribute a patch and get a couple of reviews (preferably with a benchmark of the process on a site with a few thousand aliases) and then we can see about inclusion.
Thanks for the idea.
#2
I think this would be a nice thing to do so I'm assigning it to myself for 5.x-2.1.
If someone needs it sooner than I get to it, feel free to provide your own patch.
#3
Ok, the attached patch now provides this feature.
Testing and reviews are quite welcome.
I provided it as bookpathalias instead of bookpath-alias since we don't use hyphens for alias anywhere else.
#4
Applied to both the 5.x-2.x and trunk.
#5
Automatically closed -- issue fixed for two weeks with no activity.
#6
I had some problems with this feature in the Drupal 6.1 version. I used a 'page' node as an entry in a book. Then the node-type is not 'book'. And the bookpathalias will not be resolved. This is how i fixed it:
From line 400 pathauto.module:
<?php// We're on a node and it's part of a book and it has book id set? Get the book path alias
if (module_exists('book')) {
if (isset($object->book) && !empty($object->book['bid']) && $object->nid != $object->book['bid']) {
$values['bookpathalias'] = drupal_get_path_alias('node/'. $object->book['bid']);
}
else {
$values['bookpathalias'] = '';
}
}
?>
(edit:) Changed code: Don't generate bookpath alias if nid == bid