I am using
Pattern for all Book page paths
[node:bookpathalias]/[node:title]
I add a book page called "Colours" and in book outline > create a new book
expecting to get a url
domain.com/colours
but actually get
domain.com/node/14/colours
creating a child page for this book called "Yellow" gives a url of
domain.com/node/14/colours/yellow instead of domain.com/colours/yellow

Comments

dave reid’s picture

Assigned: Unassigned » dave reid

Confirmed. On it and tracking it down.

dave reid’s picture

OMG... Looking at our bookalias token code and I'm struggling to figure out why it's so complex.

We currently have:

          // Get the bookpathalias token
          $values['bookpathalias'] = '';
          // We're on a node and it's a book and it has a parent? Get the book path alias.
          if (module_exists('book') && !empty($object->book['menu_name'])) {
            for ($i = 1; $i < 10; $i++) {
              $second_child = $i + 2;
              if (!$object->book["p$second_child"]) {
                $parent_node = db_result(db_query('SELECT link_path FROM {menu_links} WHERE mlid = %d', $object->book["p$i"]));
                break;
              }
            $values['bookpathalias'] = drupal_get_path_alias($parent_node);
          }

When we *have* the parent information right in $node->book['plid'] (same thing book.module uses when creating its 'Up' navigation link on book pages).

      $values['bookpathalias'] = '';
      if (!empty($object->book['plid'])) {
        $parent_link = db_result(db_query("SELECT link_path FROM {menu_links} WHERE mlid = %d", $object->book['plid']));
        $values['bookpathalias'] = drupal_get_path_alias($parent_link);
      }

Is there a reason for the complex parent calculation?

dave reid’s picture

And just to be clear, the following should be the expected behavior for this token so I can write a test for this:

Book node type pattern: [bookpathalias]/[node-title]

Node 1: First (root) page in book:
Title: Root page
Generated alias: root-page

Node 2: First sub-page of node 1
Title: First sub page
Generated alias: root-page/first-sub-page

Node 3: Second sub-page of node 1
Title Second sub page
Generated alias: root-page/second-sub-page

Node 4: First sub-sub page node 2
Title: First sub sub page
Generated alias: root-page/first-sub-page/first-sub-sub-page

dave reid’s picture

Also, what should be done if a page doesn't have an alias? Should we return the un-aliased path (e.g. 'node/2') as the bookpathalias token?

greggles’s picture

#2 - I'm not really sure how we missed that aside from "plid" not being all that intuitive.

#3 and #4 - those seem right to me.

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new3.72 KB

Here's the patch for 7.x-1.x with the very simplified parent fetching to run through the testbot. This would be backported to both 6.x branches.

dave reid’s picture

artatac’s picture

Working well now - thanks

Status: Fixed » Closed (fixed)

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