Project

General

Profile

Paste
Download (2.28 KB) Statistics
| Branch: | Revision:

root / drupal7 / modules / book / book.install @ bd0d4c5c

1
<?php
2

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

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

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

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

    
31
/**
32
 * Creates the book content type.
33
 */
34
function _book_install_type_create() {
35
  // Create an additional node type.
36
  $book_node_type = array(
37
    'type' => 'book',
38
    '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
    'custom' => 1,
42
    'modified' => 1,
43
    'locked' => 0,
44
  );
45

    
46
  $book_node_type = node_type_set_defaults($book_node_type);
47
  node_type_save($book_node_type);
48
  node_add_body_field($book_node_type);
49
  // Default to not promoted.
50
  variable_set('node_options_book', array('status'));
51
  // Use this default type for adding content to books.
52
  variable_set('book_allowed_types', array('book'));
53
  variable_set('book_child_type', 'book');
54
}
55

    
56
/**
57
 * Implements hook_schema().
58
 */
59
function book_schema() {
60
  $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
      'mlid' => array(
64
        'type' => 'int',
65
        'unsigned' => TRUE,
66
        'not null' => TRUE,
67
        'default' => 0,
68
        'description' => "The book page's {menu_links}.mlid.",
69
      ),
70
      'nid' => array(
71
        'type' => 'int',
72
        'unsigned' => TRUE,
73
        'not null' => TRUE,
74
        'default' => 0,
75
        'description' => "The book page's {node}.nid.",
76
      ),
77
      'bid' => array(
78
        'type' => 'int',
79
        'unsigned' => TRUE,
80
        'not null' => TRUE,
81
        'default' => 0,
82
        'description' => "The book ID is the {book}.nid of the top-level page.",
83
      ),
84
    ),
85
    'primary key' => array('mlid'),
86
    'unique keys' => array(
87
      'nid' => array('nid'),
88
    ),
89
    'indexes' => array(
90
      'bid' => array('bid'),
91
    ),
92
  );
93

    
94
  return $schema;
95
}