开发者

How can I modify the Book Copy module in Drupal 6 to change the name of the copy to a different name?

By default, the Book Copy module will create a new book with the same exact name as the book it is copying. This can become confusing and actually caused one of the site developers to accidentally delete the original book, which was reference in 开发者_StackOverflow中文版menus and such and left the site in a weird state.

Had the name of the copy been something other than the name of the original, then this problem would never have occurred. I dug through the code but just couldn't seem to figure it out. Any help will be greatly appreciated. Thanks!


You can use the hook_book_copy_alter() offered in book_copy_copy_book():

...
// The function signature is: hook_book_copy_alter(&$node, $oldbid, $newbid);
drupal_alter("book_copy", $node, $bid, $newbid);
...

So, in a custom module, you could implement the following to achieve a changed title on the new node:

function yourModule_book_copy_alter(&$node, $oldbid, $newbid) {
  // Adjust the title ...
  $node->title = 'Copy of ' .$node->title; // TODO: Change to the variation you want
  // ... and save the node again
  node_save($node);
}


It turned out that I figured it out before I found any answer on here. What I did was replace:

$node->title = t('Clone of !title', array('!title' => $node->title));

with:

if( $node->title == "Project Template" ){
    $node->title = "New Project From Template";
}
else{
    $node->title = t('Clone of !title', array('!title' => $node->title));
}

Inside lone_node_save() function of clone_pages.inc file associated with the node_clone module.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜