block.install 7.45 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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
  $schema['block_node_type'] = array(
    'description' => 'Sets up display criteria for blocks based on content types',
    'fields' => array(
      'module' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'description' => "The block's origin module, from {block}.module.",
      ),
      'delta' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'description' => "The block's unique delta within module, from {block}.delta.",
      ),
      'type' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'description' => "The machine-readable name of this type from {node_type}.type.",
      ),
    ),
    'primary key' => array('module', 'delta', 'type'),
    'indexes' => array(
      'type' => array('type'),
    ),
  );

162
  $schema['box'] = array(
163
    'description' => 'Stores contents of custom-made blocks.',
164
    'fields' => array(
165 166
      'bid' => array(
        'type' => 'serial',
167
        'unsigned' => TRUE,
168
        'not null' => TRUE,
169
        'description' => "The block's {block}.bid.",
170 171 172 173 174
      ),
      'body' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
175
        'description' => 'Block contents.',
176 177 178 179 180 181
      ),
      'info' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
182
        'description' => 'Block description.',
183 184 185 186 187 188
      ),
      'format' => array(
        'type' => 'int',
        'size' => 'small',
        'not null' => TRUE,
        'default' => 0,
189
        'description' => "Block body's {filter_format}.format; for example, 1 = Filtered HTML.",
190
      )
191
    ),
192 193 194
    'unique keys' => array(
      'info' => array('info'),
    ),
195 196 197 198
    'primary key' => array('bid'),
  );

  $schema['cache_block'] = drupal_get_schema_unprocessed('system', 'cache');
199
  $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.';
200 201

  return $schema;
202 203
}

204
/**
205
 * Implement hook_install().
206 207 208
 */
function block_install() {
  drupal_install_schema('block');
209 210

  // Block should go first so that other modules can alter its output
211 212 213
  // 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')
214
    ->fields(array('weight' => -5))
215 216
    ->condition('name', 'block')
    ->execute();
217 218 219
}

/**
220
 * Implement hook_uninstall().
221 222 223 224
 */
function block_uninstall() {
  drupal_uninstall_schema('block');
}
225 226 227

/**
 * Set system.weight to a low value for block module.
228 229
 *
 * Block should go first so that other modules can alter its output
230 231 232 233 234 235 236 237
 * 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;
}