book.install 2.28 KB
Newer Older
1 2
<?php

3 4 5 6 7
/**
 * @file
 * Install, update and uninstall functions for the book module.
 */

8
/**
9
 * Implements hook_install().
10
 */
11
function book_install() {
Dries's avatar
Dries committed
12 13
  // Add the node type.
  _book_install_type_create();
14
}
15 16

/**
17
 * Implements hook_uninstall().
18 19
 */
function book_uninstall() {
20 21 22 23
  variable_del('book_allowed_types');
  variable_del('book_child_type');
  variable_del('book_block_mode');

Dries's avatar
Dries committed
24
  // Delete menu links.
25 26 27
  db_delete('menu_links')
    ->condition('module', 'book')
    ->execute();
Dries's avatar
Dries committed
28
  menu_cache_clear_all();
29
}
Dries's avatar
Dries committed
30

31 32 33
/**
 * Creates the book content type.
 */
Dries's avatar
Dries committed
34
function _book_install_type_create() {
35
  // Create an additional node type.
Dries's avatar
Dries committed
36 37 38
  $book_node_type = array(
    'type' => 'book',
    'name' => t('Book page'),
39
    'base' => 'node_content',
40
    'description' => t('<em>Books</em> have a built-in hierarchical navigation. Use for handbooks or tutorials.'),
41 42 43
    'custom' => 1,
    'modified' => 1,
    'locked' => 0,
Dries's avatar
Dries committed
44 45
  );

46
  $book_node_type = node_type_set_defaults($book_node_type);
Dries's avatar
Dries committed
47
  node_type_save($book_node_type);
48
  node_add_body_field($book_node_type);
Dries's avatar
Dries committed
49 50 51 52 53 54 55
  // 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');
}

56
/**
57
 * Implements hook_schema().
58 59 60
 */
function book_schema() {
  $schema['book'] = array(
61
  'description' => 'Stores book outline information. Uniquely connects each node in the outline to a link in {menu_links}',
62
    'fields' => array(
63 64 65 66 67
      'mlid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
68
        'description' => "The book page's {menu_links}.mlid.",
69 70 71 72 73 74
      ),
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
75
        'description' => "The book page's {node}.nid.",
76 77 78 79 80 81
      ),
      'bid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
82
        'description' => "The book ID is the {book}.nid of the top-level page.",
83
      ),
84
    ),
85 86 87 88
    'primary key' => array('mlid'),
    'unique keys' => array(
      'nid' => array('nid'),
    ),
89
    'indexes' => array(
90
      'bid' => array('bid'),
91 92 93 94 95
    ),
  );

  return $schema;
}