Index: skeleton_instance.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/skeleton/skeleton_instance.inc,v retrieving revision 1.19 diff -u -r1.19 skeleton_instance.inc --- skeleton_instance.inc 30 Apr 2009 00:34:57 -0000 1.19 +++ skeleton_instance.inc 15 May 2009 03:28:26 -0000 @@ -701,6 +701,15 @@ $node = array(); $node['values'] = unserialize($nodes[0]->node_data); + // Pathauto provides a 'bookpathalias' token which is very useful for + // generating inline URL's. However, the path isn't generated until the + // node is saved. Escape out the token if it exists, and replace it later + // after the node is saved for the first time. + if (module_exists('pathauto')) { + $node['values']['title'] = str_replace('[bookpathalias]', '[\skeleton-bookpathalias\]', $node['values']['title']); + $node['values']['body'] = str_replace('[bookpathalias]', '[\skeleton-bookpathalias\]', $node['values']['body']); + } + // Replace custom tokens in the title and body fields. Replace skeleton // tokens first so they may be used as node tokens such as [title]. if (!empty($form_state['values']['skeleton_tokens'])) { @@ -746,28 +755,52 @@ // TODO: This will probably need to be removed if this call is integrated // into the book module. See http://drupal.org/node/364529 for details. menu_rebuild(); + $parent_node = node_load($parent_node['nid'], NULL, TRUE); + + // Only do this if pathauto exists, as it involves another save slowing + // things down. + if (module_exists('pathauto')) { + $parent_node->title = str_replace('[\skeleton-bookpathalias\]', drupal_get_path_alias($parent_node->path), $parent_node->title); + $parent_node->teaser = str_replace('[\skeleton-bookpathalias\]', drupal_get_path_alias($parent_node->path), $parent_node->teaser); + $parent_node->body = str_replace('[\skeleton-bookpathalias\]', drupal_get_path_alias($parent_node->path), $parent_node->body); + $parent_node->skeleton_template->keep_connected = TRUE; + $parent_node = node_submit($parent_node); + node_save($parent_node); + } + // get the id we just created - $form_state['nids'][] = $parent_node['nid']; - $book_id = $parent_node['nid']; + $form_state['nids'][] = $parent_node->nid; + $book_id = $parent_node->nid; $goto_id = $book_id; - // iterate through the dummy nodes and create the book pages + + // Iterate through the dummy nodes and create the book pages. // The Book ID is the NID of the topmost book page. foreach ($nodes as $data) { $node = array(); $node['values'] = unserialize($data->node_data); // if parents are assigned by the skeleton, use them if ($data->parent > 0 && isset($parents[$data->parent])) { - $parent_node = node_load($parents[$data->parent]); + $parent_node = node_load($parents[$data->parent], NULL, TRUE); } else { - $parent_node = node_load($book_id); + $parent_node = node_load($book_id, NULL, TRUE); } $node['values']['book'] = array(); $node['values']['book']['bid'] = $book_id; $node['values']['book']['plid'] = $parent_node->book['mlid']; + $node['values']['book']['weight'] = $data->weight; $node['values']['book']['options'] = array(); + // For subpages, we can simply simulate the [bookpathalias] token here. + // Otherwise, it will be replaced with '' during token_replace() as the + // node isn't saved yet. + if (module_exists('pathauto')) { + $book_root = node_load($book_id); + $node['values']['title'] = str_replace('[bookpathalias]', drupal_get_path_alias($book_root->path), $node['values']['title']); + $node['values']['body'] = str_replace('[bookpathalias]', drupal_get_path_alias($book_root->path), $node['values']['body']); + } + // Replace custom tokens in the title and body fields. Replace skeleton // tokens first so they may be used as node tokens such as [title]. if (!empty($form_state['values']['skeleton_tokens'])) {