Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal: Changes in Book Module in Drupal 6

Submitted by on July 30, 2010 – 2:59 amNo Comment

This article describes how to find and understand changes in Book module. This will make you able to adapt snippets and modules which interact with Books module in Drupal 6.


Solution

Drupal 5.х

IN Drupal  5.x, when storing book page, a record is created in “node” table of “book” type and the respective record is created in “book” table (nid) to define relation to a parent page. If parent is set to 0, this book is from top level. So simple!

All module info is stored in one table:

CREATE TABLE book (
        vid int unsigned NOT NULL default ‘0’,
        nid int unsigned NOT NULL default ‘0’,
        parent int NOT NULL default ‘0’,
        weight tinyint NOT NULL default ‘0’,
        PRIMARY KEY (vid),
        KEY nid (nid),
        KEY parent (parent)
)

Drupal 6.х

IN 6.x "book" table contains only nid, bid and mlid fields now.

As you can see in Drupal interface, it is impossible to specify parent page on node/add/book page. You should select the existing book and NECESSARY parent page in this book.

Book module was changed to use new menu system

Book uses new menu system Drupal 6.x now ({menu_links} table) for storing and recovering book hierarchy. Any modules which worked through Book interface earlier have to be rewritten. All information stored  in a node by Book module is in $node->book property now.

Many API functions of Book module were changed. For example, book_recurse function was deleted. For the most cases it can be replaced with book_export_traverse but it has no $depth parameter.

Taтабle analysis in database

– `book` table structure

CREATE TABLE `book` (
  `mlid` int(10) unsigned NOT NULL default ‘0’,
  `nid` int(10) unsigned NOT NULL default ‘0’,
  `bid` int(10) unsigned NOT NULL default ‘0’,
  PRIMARY KEY  (`mlid`),
  UNIQUE KEY `nid` (`nid`),
  KEY `bid` (`bid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

– `menu_links` table structure

CREATE TABLE `menu_links` (
  `menu_name` varchar(32) NOT NULL default ”,
  `mlid` int(10) unsigned NOT NULL auto_increment,
  `plid` int(10) unsigned NOT NULL default ‘0’,
  `link_path` varchar(255) NOT NULL default ”,
  `router_path` varchar(255) NOT NULL default ”,
  `link_title` varchar(255) NOT NULL default ”,
  `options` text,
  `module` varchar(255) NOT NULL default ‘system’,
  `hidden` smallint(6) NOT NULL default ‘0’,
  `external` smallint(6) NOT NULL default ‘0’,
  `has_children` smallint(6) NOT NULL default ‘0’,
  `expanded` smallint(6) NOT NULL default ‘0’,
  `weight` int(11) NOT NULL default ‘0’,
  `depth` smallint(6) NOT NULL default ‘0’,
  `customized` smallint(6) NOT NULL default ‘0’,
  `p1` int(10) unsigned NOT NULL default ‘0’,
  `p2` int(10) unsigned NOT NULL default ‘0’,
  `p3` int(10) unsigned NOT NULL default ‘0’,
  `p4` int(10) unsigned NOT NULL default ‘0’,
  `p5` int(10) unsigned NOT NULL default ‘0’,
  `p6` int(10) unsigned NOT NULL default ‘0’,
  `p7` int(10) unsigned NOT NULL default ‘0’,
  `p8` int(10) unsigned NOT NULL default ‘0’,
  `p9` int(10) unsigned NOT NULL default ‘0’,
  `updated` smallint(6) NOT NULL default ‘0’,
  PRIMARY KEY  (`mlid`),
  KEY `path_menu` (`link_path`(128),`menu_name`),
  KEY `menu_plid_expand_child` (`menu_name`,`plid`,`expanded`,`has_children`),
  KEY `menu_parents` (`menu_name`,`p1`,`p2`,`p3`,`p4`,`p5`,`p6`,`p7`,`p8`,`p9`),
  KEY `router_path` (`router_path`(128))
) ENGINE=MyISAM AUTO_INCREMENT=407 DEFAULT CHARSET=utf8 AUTO_INCREMENT=407 ;

$node->book analysis

Let’s create a document of Book type and execute a code there (input format should be PHP):

if ((arg(0) == ‘node’) && is_numeric(arg(1))) {
$node = node_load(arg(1));
var_dump($node->book);
}

Here is the result:

array(29) {
  ["mlid"]=> string(3) "409"
  ["nid"]=> string(2) "27"
  ["bid"]=> string(2) "56"
  ["menu_name"]=> string(11) "book-toc-56"
  ["plid"]=> string(3) "257"
  ["link_path"]=> string(7) "node/27"
  ["router_path"]=> string(6) "node/%"
  ["link_title"]=> string(20) "Содержание"
  ["options"]=> array(0) {}
  ["module"]=> string(4) "book"
  ["hidden"]=> string(1) "0"
  ["external"]=> string(1) "0"
  ["has_children"]=> string(1) "0"
  ["expanded"]=> string(1) "0"
  ["weight"]=> string(1) "0"
  ["depth"]=> string(1) "2"
  ["customized"]=> string(1) "0"
  ["p1"]=> string(3) "257"
  ["p2"]=> string(3) "409"
  ["p3"]=> string(1) "0"
  ["p4"]=> string(1) "0"
  ["p5"]=> string(1) "0"
  ["p6"]=> string(1) "0"
  ["p7"]=> string(1) "0"
  ["p8"]=> string(1) "0"
  ["p9"]=> string(1) "0"
  ["updated"]=> string(1) "0"
  ["href"]=> string(7) "node/27"
  ["title"]=> string(20) "Содержание"
}

Summary
  • book table in Drupal 6.х contains bid field (Book id) which stores  nid of a page of the top book level.
  • Every book page has mlid field (Menu links id) for connection with menu_links table.
    It is necessary because page hierarchy is now realized in menu_links rather than in booktable.
  • Maximum inclusion is limited by 9 levels.
$node->book array elements
  • mlid – id menu_links, allows Book module to connect to menu_links
  • nid – node id
  • bid – abbreviation of "book_id"
  • menu_name – for all Book documents, always begins from "book-toc-" + nid of top-level document. menu_name is similar for all documents for one book.
  • plid – mlid of parent (0 – top level)
  • link_path – document address in menu
  • router_path
  • link_title – link text in menu
  • options array(0) {}
  • module – system module name. It is stored in menu_links.module
  • hidden – hidden menu element
  • external
  • has_children – if there are child documents (0 – no, 1 – yes)
  • expanded – if it is expanded (0- no, 1 – yes)
  • weight – weight (it is used for sorting of one-level elements)
  • depth – depth of inclusion (1 – top level)
  • customized
  • p1 – top level in menu hierarchy. Contains parent mlid
  • p2 – hierarchy level. IN our case it contains mlid of current node
  • p3 – 0 – if there are no child nodes.
  • p4
  • p5
  • p6
  • p7
  • p8
  • p9
  • updated
  • href – document address
  • title – document header

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.