block.install 6.61 KB
Newer Older
1 2 3
<?php
// $Id$

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

9
/**
10
 * Implement hook_schema().
11 12
 */
function block_schema() {
13
  $schema['block'] = array(
14
    'description' => 'Stores block settings, such as region and visibility settings.',
15
    'fields' => array(
16 17 18
      'bid' => array(
        'type' => 'serial',
        'not null' => TRUE,
19
        'description' => 'Primary Key: Unique block ID.',
20 21 22 23 24 25
      ),
      'module' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
26
        'description' => "The module from which the block originates; for example, 'user' for the Who's Online block, and 'block' for any custom blocks.",
27 28 29 30 31 32
      ),
      'delta' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '0',
33
        'description' => 'Unique ID for block within a module.',
34 35 36
      ),
      'theme' => array(
        'type' => 'varchar',
37
        'length' => 64,
38 39
        'not null' => TRUE,
        'default' => '',
40
        'description' => 'The theme under which the block settings apply.',
41 42 43 44 45 46
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
47
        'description' => 'Block enabled status. (1 = enabled, 0 = disabled)',
48 49 50 51 52 53
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
54
        'description' => 'Block weight within region.',
55 56 57 58 59
      ),
      'region' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
60
        'default' => '',
61
        'description' => 'Theme region within which the block is set.',
62 63 64 65 66 67
      ),
      'custom' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
68
        'description' => 'Flag to indicate how users may control visibility of the block. (0 = Users cannot control, 1 = On by default, but can be hidden, 2 = Hidden by default, but can be shown)',
69 70 71 72 73 74
      ),
      'visibility' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
75
        'description' => 'Flag to indicate how to show blocks on pages. (0 = Show on all pages except listed pages, 1 = Show only on listed pages, 2 = Use custom PHP code to determine visibility)',
76 77 78 79
      ),
      'pages' => array(
        'type' => 'text',
        'not null' => TRUE,
80
        'description' => 'Contents of the "Pages" block; contains either a list of paths on which to include/exclude the block or PHP code, depending on "visibility" setting.',
81 82 83 84 85 86
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
87
        'description' => 'Custom title for the block. (Empty string will use block default title, &lt;none&gt; will remove the title, text will cause block to use specified title.)',
88 89 90 91
      ),
      'cache' => array(
        'type' => 'int',
        'not null' => TRUE,
92
        'default' => 1,
93
        'size' => 'tiny',
94
        'description' => 'Binary flag to indicate block cache mode. (-1: Do not cache, 1: Cache per role, 2: Cache per user, 4: Cache per page, 8: Block cache global) See BLOCK_CACHE_* constants in block.module for more detailed information.',
95
      ),
96 97
    ),
    'primary key' => array('bid'),
98 99 100 101 102 103
    'unique keys' => array(
      'tmd' => array('theme', 'module', 'delta'),
    ),
    'indexes' => array(
      'list' => array('theme', 'status', 'region', 'weight', 'module'),
    ),
104 105
  );

106
  $schema['block_role'] = array(
107
    'description' => 'Sets up access permissions for blocks based on user roles',
108
    'fields' => array(
109 110 111 112
      'module' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
113
        'description' => "The block's origin module, from {block}.module.",
114
      ),
115
      'delta' => array(
116 117 118
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
119
        'description' => "The block's unique delta within module, from {block}.delta.",
120 121 122 123 124
      ),
      'rid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
125
        'description' => "The user's role ID from {users_roles}.rid.",
126
      ),
127
    ),
128
    'primary key' => array('module', 'delta', 'rid'),
129 130 131
    'indexes' => array(
      'rid' => array('rid'),
    ),
132 133
  );

134
  $schema['box'] = array(
135
    'description' => 'Stores contents of custom-made blocks.',
136
    'fields' => array(
137 138
      'bid' => array(
        'type' => 'serial',
139
        'unsigned' => TRUE,
140
        'not null' => TRUE,
141
        'description' => "The block's {block}.bid.",
142 143 144 145 146
      ),
      'body' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
147
        'description' => 'Block contents.',
148 149 150 151 152 153
      ),
      'info' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
154
        'description' => 'Block description.',
155 156 157 158 159 160
      ),
      'format' => array(
        'type' => 'int',
        'size' => 'small',
        'not null' => TRUE,
        'default' => 0,
161
        'description' => "Block body's {filter_format}.format; for example, 1 = Filtered HTML.",
162
      )
163
    ),
164 165 166
    'unique keys' => array(
      'info' => array('info'),
    ),
167 168 169 170
    'primary key' => array('bid'),
  );

  $schema['cache_block'] = drupal_get_schema_unprocessed('system', 'cache');
171
  $schema['cache_block']['description'] = 'Cache table for the Block module to store already built blocks, identified by module, delta, and various contexts which may change the block, such as theme, locale, and caching mode defined for the block.';
172 173

  return $schema;
174 175
}

176
/**
177
 * Implement hook_install().
178 179 180
 */
function block_install() {
  drupal_install_schema('block');
181 182

  // Block should go first so that other modules can alter its output
183 184 185 186 187 188 189 190
  // during hook_page_alter(). Almost everything on the page is a block,
  // so before block module runs, there will not be much to alter.
  db_update('system')
    ->fields(array(
      'weight' => -5,
    ))
    ->condition('name', 'block')
    ->execute();
191 192 193
}

/**
194
 * Implement hook_uninstall().
195 196 197 198
 */
function block_uninstall() {
  drupal_uninstall_schema('block');
}
199 200 201

/**
 * Set system.weight to a low value for block module.
202 203
 *
 * Block should go first so that other modules can alter its output
204 205 206 207 208 209 210 211
 * during hook_page_alter(). Almost everything on the page is a block,
 * so before block module runs, there will not be much to alter.
 */
function block_update_7000() {
  $ret = array();
  $ret[] = update_sql("UPDATE {system} SET weight = -5 WHERE name = 'block'");
  return $ret;
}