Book tokens broken in Drupal 6

mikeryan - February 18, 2008 - 21:13
Project:Token
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:mikeryan
Status:closed
Description

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
    <?php
    $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?).

#1

mikeryan - February 19, 2008 - 02:56
Status:active» patch (code needs review)

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?

AttachmentSize
token_node.inc_.patch2.96 KB

#2

mikeryan - February 20, 2008 - 02:31

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

#3

greggles - February 23, 2008 - 11:24
Status:patch (code needs review)» patch (code needs work)

Ok - sounds good. Thanks mike.

#4

mikeryan - February 24, 2008 - 22:33
Status:patch (code needs work)» patch (code needs review)

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

AttachmentSize
token_node.inc_.patch3.71 KB

#5

mikeryan - March 8, 2008 - 22:31
Assigned to:Anonymous» mikeryan

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

AttachmentSize
token_node.inc_.patch4.65 KB

#6

greggles - April 6, 2008 - 13:56

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.

#7

mikeryan - April 6, 2008 - 14:03

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.

#8

John Morahan - April 22, 2008 - 11:26

Here's an attempt at an updated patch.

AttachmentSize
token-book.patch4.67 KB

#9

mikeryan - April 23, 2008 - 00:40
Status:patch (code needs review)» fixed

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

#10

MikeQue - May 6, 2008 - 18:14

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.

#11

Anonymous (not verified) - May 20, 2008 - 18:21
Status:fixed» closed

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

#12

zukalous - May 21, 2008 - 05:48

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?

 
 

Drupal is a registered trademark of Dries Buytaert.