How to make a duplicate Book module
Note that in Drupal 5.x can use the outline module to achieve the same thing.
Why Do It?
For my particular application I noted a few pros/cons.
Pros
- have something other than 'book page' appear in the search results (e.g. Employee Handbook)
- use along with an access module (e.g. Node Access) to restrict different roles to different book instances
Cons
- After doing this tutorial the core 'printer-friendly version' functionality will be lost. If you know how to fix this please comment or send me a message.
How to Do it
Preparing the Original Book Module to Work with a Duplicate
- make sure the book module deactivated on your site.
- duplicate the book module and place a copy in your site's /sites/default/modules directory. You may need to create the modules directory.
- open up the duplicated file in a text editor use the find-replace tool to replace all instances of
if ($type == 'node' && isset($node->parent)) {withif ($type == 'node' && isset($node->parent) && $node->type == 'book') {so the book module isn't confused with the new duplicated one. - delete line 2 beginning with
// $Id: book.modulebecause it isn't needed. - Now it's ok to activate the book module. Drupal looks in ths /sites/default/modules directory before looking in the /modules directory so it will ignore the original script.
Duplicating the book module into a new module
figure out what you want the name of the book type to be called. if it's more than one word it will need to contain an underscore. I'll use the convention new_book_type in the rest of this tutorial.
- Open up the file you created above and copy the contents to a new file called new_book_type.module
- use the find-replace tool to replace all instances of book with new_book_type
- save the file and upload to your /sites/default/modules directory.
- create a new table in your database using the following SQL query
CREATE TABLE `<b>new_book_type</b>` (
`vid` int( 10 ) unsigned NOT NULL default '0',
`nid` int( 10 ) unsigned NOT NULL default '0',
`parent` int( 10 ) NOT NULL default '0',
`weight` tinyint( 3 ) NOT NULL default '0',
PRIMARY KEY ( `vid` ) ,
KEY `nid` ( `nid` ) ,
KEY `parent` ( `parent` )
) ENGINE = MYISAM DEFAULT CHARSET = utf8 - Enable the module.
Other things you may want to do
- If the module doesn't appear once you enable it you have an error in your new module. Start over and try again
- Go to the end of the new file and reword the help text and other instructional text so it is appropriate (e.g. update "A book is a collaborative writing effort: ..." to whatever)
- Edit your CSS stylesheet to include the new classes or you can style the new module differently
