book.install 2.33 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() {
Dries's avatar
Dries committed
20
  // Delete menu links.
21 22 23
  db_delete('menu_links')
    ->condition('module', 'book')
    ->execute();
Dries's avatar
Dries committed
24
  menu_cache_clear_all();
25
}
Dries's avatar
Dries committed
26

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

42
  $book_node_type = node_type_set_defaults($book_node_type);
Dries's avatar
Dries committed
43
  node_type_save($book_node_type);
44
  node_add_body_field($book_node_type);
Dries's avatar
Dries committed
45 46 47 48
  // Default to not promoted.
  variable_set('node_options_book', array('status'));
}

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

  return $schema;
}
89 90 91 92 93 94 95 96 97 98 99 100 101

/**
 * Move book settings from variables to config.
 *
 * @ingroup config_upgrade
 */
function book_update_8000() {
  update_variables_to_config('book.settings', array(
    'book_allowed_types' => 'allowed_types',
    'book_child_type' => 'child_type',
    'book_block_mode' => 'block.navigation.mode',
  ));
}