In pathauto, set a pattern of books/[book-raw]/[title-raw] for Book page paths. Create a book page titled Test - you'll get a path of (precisely) books/[book-raw]/test. A couple of issues here in book_token_values():

  1. Easy one - if the else clause included $tokens['book-raw'] = ''; at least the token would be omitted and you'd get books/test.
  2. Harder one - both $node->parent and book_location() are obsolete in Drupal 6.

OK, my bad for using an internal book.module function in the first place... It looks like there is no equivalent function at the moment, but you can dig into the node structure... $node->book['bid'] is the node ID of the book, $node->book['mlid'] is that node's menu link ID, and $node->book['plid'] is the parent's menu link ID.

I'll take a quick stab at generating a patch for this (good practice getting up to speed on Drupal 6)... Of course, this is vulnerable to future change in the book module - I think it would be good for the book module to support an official API so other modules can traverse the hierarchy (or am I missing something that already exists?).

Comments

mikeryan’s picture

Status: Active » Needs review
StatusFileSize
new2.96 KB

OK, here's a patch against revision 1.5.4.2 - I've reimplemented the Drupal 5 book_location() as _book_location(). Not sure whether it's worth proposing adding this to the book module, thoughts?

mikeryan’s picture

The patch needs a little more work, I had tunnel vision when developing it and was creating only book nodes, it generates an error with other node types. Simple fix for this, but I need to test more thoroughly. And also patch against the latest revision...

greggles’s picture

Status: Needs review » Needs work

Ok - sounds good. Thanks mike.

mikeryan’s picture

Status: Needs work » Needs review
StatusFileSize
new3.71 KB

OK, here's a better patch. No errors with other node types. Also, allowed for the new Drupal 6 behavior where you can create a book node which is not part of a book (previously a book node without a parent was automatically the top of a new book - you need to explicitly make it so now).

mikeryan’s picture

Assigned: Unassigned » mikeryan
StatusFileSize
new4.65 KB

Here's yet a better patch - uses menu APIs instead of querying the database directly, and shares code with the menu path fix.

greggles’s picture

I did some quick testing of the bookpath-raw token and it seems to work.

For the book_token_values, though, it looks like it will try to assign values to those regardless of whether or not it is in a book hierarchy (that's what the if ($node->parent) { was trying to check in Drupal5).

@mikeryan - what do you think, did you get rid of that for a specific reason? I feel like we should probably include that and also include setting the values to '' if the node is not in an outline.

mikeryan’s picture

Not a matter of intent, but the old-school assumption that a book node must be part of a book... I'll update the patch this week.

Thanks.

john morahan’s picture

StatusFileSize
new4.67 KB

Here's an attempt at an updated patch.

mikeryan’s picture

Status: Needs review » Fixed

Thanks John - I've let this lie too long, I've committed your patch to the DRUPAL-6--1 branch.

mikeque’s picture

thanks, I installed the development updates of token and pathauto. this seems to work in pathauto with book-raw now. That serves my purposes, but FYI I did notice that other token values still seem to fail.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

zukalous’s picture

Applying the latest token-book.patch failed forme. I used CYGWIN to patch and it says

Hunk #2 failed at 187. 
1 out of 2 hunks FAILED -- saving rejects to file token_node.inc.rej

I am new to Drupal and this is the first time I have every tried to apply a patch so it could be user error. But, when I try to load my Drupal 6 site with the patch applied I get the following error:

Fatal error: require_once() [function.require]: Failed opening required 'sites/test_multi.localhost/modules/token/token_node.inc' (include_path='.;C:\xampp\php\pear\') in C:\xampp\htdocs\drupal-6\sites\test_multi.localhost\modules\token\token.module on line 113

Am I just showing my newbness or is this a real problem with the patch?

guillaumeduveau’s picture

Category: bug » support
Status: Closed (fixed) » Active

Still broken for me on Tokens 6.x-1.12 + Pathauto 6.x-1.x-dev (2009-08-14)

Anonymous’s picture

Priority: Normal » Critical

Still broken.
Pathauto 6.x-1.x-dev (2009-dec-04)
Token 6.x-1.x-dev (2009-dec-23)

I changed it to priority critical.

dave reid’s picture

Priority: Critical » Normal
Status: Active » Postponed (maintainer needs more info)

Please provide details as to why this is still broken or instructions to reproduce a bug.

dave reid’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

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