I'm developing a module for Drupal 6.x that has its own content type. This content type should never ever ever be part of a book, so I don't want "Book Outline" to show up in the create content page at all.

Is there a code-y way to make that block disappear from this content type entirely?

Comments

mooffie’s picture

'Book' comes with a settings page that lets the admin select which content-types are allowed in a book. These are stored in the 'book_allowed_types' variable. So in you hook_install append your content-type to this list.

Or, if the name of your content-type is dynamic, imlemenet hook_form_alter and put an '#access' => FALSE on the Outline box. To get rid of the 'Outline' tab, implement hook_menu_alter.

lishevita’s picture

OK, after reading moofie's reply, I found http://groups.drupal.org/node/4308 which was helpful.

Now how do I find out what the name of the Outline tab is? I've been looking at the source to try to guess at it. This does not work:

function fring_addon_form_alter() {
if($form_id == "edit-fring-addon-node-form") {
$form['edit-book-bid'] = array( //this is the piece that I don't know how to find the right name for!!!
'#access' => 'false',
);
}
}

mooffie’s picture

We have two things to get rid of: the Outline box, and the Outline tab.

To get rid of the Outline box, which is shown in a form, we use hook_form_alter:

function mymodule_form_alter(&$form, $form_state, $form_id) {
  // Is this a node editing form?
  if (isset($form['type']) && isset($form['#node']) && 
      $form['type']['#value'] .'_node_form' == $form_id) {
    // Yep!
    // If it's a 'story' node, remove the Book Outline box:
    if ($form['type']['#value'] == 'story') {
      $form['book']['#access'] = FALSE;
    }
  }
}

(Change 'mymodule' to the name of your module. And 'story' to your special node-type(s).)

Now we have to get rid of the Outline tab.

The outline tab is 'node/%node/outline' (we learn this by a cursory look at book's source code). That's a menu item. We want to modify this menu item so that it doens't show on 'story' nodes. We do this modification in hook_alter_menu:

function mymodule_menu_alter(&$callbacks) {
  // for debugging:
  drupal_set_message("I'm modifying the outline tab");

  // Every menu item has an 'access callback' that determines
  // whether this menu/tab will be accessible/shown.
  //
  // We install our own access callback:
  $callbacks['node/%node/outline']['access callback'] = '_mymodule_restrict_outline_tab';
}

// Additional access control for the 'Outline' tab: don't show for 'story' nodes...
function _mymodule_restrict_outline_tab($node) {
  if ($node->type == 'story') {
    return FALSE;
  }
  // Delegate to the original access callback:
  return _book_outline_access($node);
}

(Again, change 'mymodule' and 'story'...)

A note about hook_menu_alter: Drupal caches the menu, so this hook is called only when Drupal rebuilds the menu. To trigger this rebuilding you'll have to clear Drupal's cache. This is done automatically when installing a module, but you'll have to do this manually now (tip: the 'Devel' module provides a 'clear cache' command). You should see a "I'm modifying the.." message once.

geshan’s picture

Thanks for the code I made it a small module with code similar to above :), I guess you should add some settings and contribute the module.

geshan’s picture

I coded a small module with some parts of your code:here - it has a configuration page to select which node types to show the book outline form and menu for. Hope it helps.