Skip to main content
Drupal has a good potential to be used as a blog, forum (some what), wiki or any other dedicated web application or combination of two or more services. Drupal as a wiki, out of the box is a little weird. Problem is Drupal organizes wiki as book pages and books and book pages are related. Some people might not agree that book node/content type is a form of wiki but they can be used as one.


Problem:

The problem using Drupal book module and book pages as wiki is, the book page module adds book outline form part and the book outline menu as node/x/outline to all node types. All the node types do not need to be part of a book/wiki page. So this is the awkward part. I had to develop an application that had a wiki as a part with blogs and events as other services. So I faced this problem.

The Search:

Then I searched for the solution to show book outline form part and the book outline module in only specified Drupal nodes/content types. At the d.o (I hear this in all screencasts and podcasts - its Drupal.org ;) ) site I found this node: http://drupal.org/node/251798 - and a code snippet by mooffie. But the code was very basic and not configurable or flexible.

A Simple Move:

I decided to use the code as it was a solution to my problem but also thought to make a configurable module out of it. So the module is called nobookoutline now, I have not put it in d.o as I'm not confident of getting a CVS account :). Here is the download link for the module.

The Solution:

The module provides a user interface to select which node/content types you want to show the book outline form and /outline menu option to. Below is the screen-shot of the page you can see in Admin>> Content>> Book Outline Settings after you download and enable the module and login as site admin. you can access the page by going to  admin/content/nobookoutline.


After you select the appropriate node types and click save the book outline form and the menu node/x/outline will only appear on the desired node types. Like below:




Below is a book node that has outline, other nodes will not have the outline menu unless they are selected in the configuration page.


The book outline menu appears only for selected node types.

Edited Code:

The code has been edited to accommodate the new configuration page and here is a snippet below:

<?php


/**
* Implementation of hook_form_alter
* @param $form
* @param $form_state
* @param $form_id
* @return NULL
*/
function nobookoutline_form_alter(&$form, $form_state, $form_id) {

if (isset($form['#node']) && $form_id == $form['#node']->type .'_node_form') {
$node = $form['#node'];
// If it's not a book node, remove the Book Outline box:
// now get settings as set.
$nodetypes = variable_get('form_nobookoutline_nodetypes', array('book'));
if(!in_array($node->type, $nodetypes)) {
$form['book']['#access'] = FALSE;
}
}
}


/**
* implementation of hook_menu_alter
* @param $callbacks
* @return unknown_type
*/
function nobookoutline_menu_alter(&$callbacks) {
// We install our own access callback to check if node is book type
$callbacks['node/%node/outline']['access callback'] = '_nobookoutline_restrict_outline_tab';
}

// Additional access control for the 'Outline' tab: don't show for non 'book' nodes...
function _nobookoutline_restrict_outline_tab($node) {
$nodetypes = variable_get('form_nobookoutline_nodetypes', array('book'));

if(!in_array($node->type, $nodetypes)) {

return FALSE;
}
// Delegate to the original access callback:
return _book_outline_access($node);
}


?>


What the code does is, it just restricts access to the form part and the menu link.

Conclusion

The module can be made better with permissions but is functional enough for now. Hope it solves your problem.


Using Drupal as a wiki will not be a big deal if this minor issue is resolved. Happy Drupalling.

Comments