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.

CommentFileSizeAuthor
#3 bookpathalias_144366.patch1.6 KBgreggles

Comments

greggles’s picture

Title: bookpath » provide [bookpath-alias] token
Version: 5.x-1.1 » 5.x-2.x-dev
Category: task » feature

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.

greggles’s picture

Assigned: Unassigned » greggles

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.

greggles’s picture

Title: provide [bookpath-alias] token » provide [bookpathalias] token
Status: Active » Needs review
StatusFileSize
new1.6 KB

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.

greggles’s picture

Status: Needs review » Fixed

Applied to both the 5.x-2.x and trunk.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

edgar83’s picture

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:

// 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