home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (book.install)

This example Drupal source code file (book.install) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, book, book_node_type, default, description, function, int, nid, null, php, the, true, unsigned

The book.install Drupal example source code

<?php
// $Id: book.install,v 1.36 2010/06/23 19:05:15 dries Exp $

/**
 * @file
 * Install, update and uninstall functions for the book module.
 */

/**
 * Implements hook_install().
 */
function book_install() {
  // Add the node type.
  _book_install_type_create();
}

/**
 * Implements hook_uninstall().
 */
function book_uninstall() {
  // Delete menu links.
  db_delete('menu_links')
    ->condition('module', 'book')
    ->execute();
  menu_cache_clear_all();
}

function _book_install_type_create() {
  // Create an additional node type.
  $book_node_type = array(
    'type' => 'book',
    'name' => t('Book page'),
    'base' => 'node_content',
    'description' => t('<em>Books</em> have a built-in hierarchical navigation. Use for handbooks or tutorials.'),
    'custom' => 1,
    'modified' => 1,
    'locked' => 0,
  );

  $book_node_type = node_type_set_defaults($book_node_type);
  node_type_save($book_node_type);
  node_add_body_field($book_node_type);
  // Default to not promoted.
  variable_set('node_options_book', array('status'));
  // Use this default type for adding content to books.
  variable_set('book_allowed_types', array('book'));
  variable_set('book_child_type', 'book');
}

/**
 * Implements hook_schema().
 */
function book_schema() {
  $schema['book'] = array(
  'description' => 'Stores book outline information. Uniquely connects each node in the outline to a link in {menu_links}',
    'fields' => array(
      'mlid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => "The book page's {menu_links}.mlid.",
      ),
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => "The book page's {node}.nid.",
      ),
      'bid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => "The book ID is the {book}.nid of the top-level page.",
      ),
    ),
    'primary key' => array('mlid'),
    'unique keys' => array(
      'nid' => array('nid'),
    ),
    'indexes' => array(
      'bid' => array('bid'),
    ),
  );

  return $schema;
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal book.install source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.