Project

General

Profile

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

root / drupal7 / profiles / standard / standard.install @ 6d8023f2

1
<?php
2
/**
3
 * @file
4
 * Install, update and uninstall functions for the standard installation profile.
5
 */
6

    
7
/**
8
 * Implements hook_install().
9
 *
10
 * Perform actions to set up the site for this profile.
11
 *
12
 * @see system_install()
13
 */
14
function standard_install() {
15
  // Add text formats.
16
  $filtered_html_format = array(
17
    'format' => 'filtered_html',
18
    'name' => 'Filtered HTML',
19
    'weight' => 0,
20
    'filters' => array(
21
      // URL filter.
22
      'filter_url' => array(
23
        'weight' => 0,
24
        'status' => 1,
25
      ),
26
      // HTML filter.
27
      'filter_html' => array(
28
        'weight' => 1,
29
        'status' => 1,
30
      ),
31
      // Line break filter.
32
      'filter_autop' => array(
33
        'weight' => 2,
34
        'status' => 1,
35
      ),
36
      // HTML corrector filter.
37
      'filter_htmlcorrector' => array(
38
        'weight' => 10,
39
        'status' => 1,
40
      ),
41
    ),
42
  );
43
  $filtered_html_format = (object) $filtered_html_format;
44
  filter_format_save($filtered_html_format);
45

    
46
  $full_html_format = array(
47
    'format' => 'full_html',
48
    'name' => 'Full HTML',
49
    'weight' => 1,
50
    'filters' => array(
51
      // URL filter.
52
      'filter_url' => array(
53
        'weight' => 0,
54
        'status' => 1,
55
      ),
56
      // Line break filter.
57
      'filter_autop' => array(
58
        'weight' => 1,
59
        'status' => 1,
60
      ),
61
      // HTML corrector filter.
62
      'filter_htmlcorrector' => array(
63
        'weight' => 10,
64
        'status' => 1,
65
      ),
66
    ),
67
  );
68
  $full_html_format = (object) $full_html_format;
69
  filter_format_save($full_html_format);
70

    
71
  // Enable some standard blocks.
72
  $default_theme = variable_get('theme_default', 'bartik');
73
  $admin_theme = 'seven';
74
  $blocks = array(
75
    array(
76
      'module' => 'system',
77
      'delta' => 'main',
78
      'theme' => $default_theme,
79
      'status' => 1,
80
      'weight' => 0,
81
      'region' => 'content',
82
      'pages' => '',
83
      'cache' => -1,
84
    ),
85
    array(
86
      'module' => 'search',
87
      'delta' => 'form',
88
      'theme' => $default_theme,
89
      'status' => 1,
90
      'weight' => -1,
91
      'region' => 'sidebar_first',
92
      'pages' => '',
93
      'cache' => -1,
94
    ),
95
    array(
96
      'module' => 'node',
97
      'delta' => 'recent',
98
      'theme' => $admin_theme,
99
      'status' => 1,
100
      'weight' => 10,
101
      'region' => 'dashboard_main',
102
      'pages' => '',
103
      'cache' => -1,
104
    ),
105
    array(
106
      'module' => 'user',
107
      'delta' => 'login',
108
      'theme' => $default_theme,
109
      'status' => 1,
110
      'weight' => 0,
111
      'region' => 'sidebar_first',
112
      'pages' => '',
113
      'cache' => -1,
114
    ),
115
    array(
116
      'module' => 'system',
117
      'delta' => 'navigation',
118
      'theme' => $default_theme,
119
      'status' => 1,
120
      'weight' => 0,
121
      'region' => 'sidebar_first',
122
      'pages' => '',
123
      'cache' => -1,
124
    ),
125
    array(
126
      'module' => 'system',
127
      'delta' => 'powered-by',
128
      'theme' => $default_theme,
129
      'status' => 1,
130
      'weight' => 10,
131
      'region' => 'footer',
132
      'pages' => '',
133
      'cache' => -1,
134
    ),
135
    array(
136
      'module' => 'system',
137
      'delta' => 'help',
138
      'theme' => $default_theme,
139
      'status' => 1,
140
      'weight' => 0,
141
      'region' => 'help',
142
      'pages' => '',
143
      'cache' => -1,
144
    ),
145
    array(
146
      'module' => 'system',
147
      'delta' => 'main',
148
      'theme' => $admin_theme,
149
      'status' => 1,
150
      'weight' => 0,
151
      'region' => 'content',
152
      'pages' => '',
153
      'cache' => -1,
154
    ),
155
    array(
156
      'module' => 'system',
157
      'delta' => 'help',
158
      'theme' => $admin_theme,
159
      'status' => 1,
160
      'weight' => 0,
161
      'region' => 'help',
162
      'pages' => '',
163
      'cache' => -1,
164
    ),
165
    array(
166
      'module' => 'user',
167
      'delta' => 'login',
168
      'theme' => $admin_theme,
169
      'status' => 1,
170
      'weight' => 10,
171
      'region' => 'content',
172
      'pages' => '',
173
      'cache' => -1,
174
    ),
175
    array(
176
      'module' => 'user',
177
      'delta' => 'new',
178
      'theme' => $admin_theme,
179
      'status' => 1,
180
      'weight' => 0,
181
      'region' => 'dashboard_sidebar',
182
      'pages' => '',
183
      'cache' => -1,
184
    ),
185
    array(
186
      'module' => 'search',
187
      'delta' => 'form',
188
      'theme' => $admin_theme,
189
      'status' => 1,
190
      'weight' => -10,
191
      'region' => 'dashboard_sidebar',
192
      'pages' => '',
193
      'cache' => -1,
194
    ),
195
  );
196
  $query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
197
  foreach ($blocks as $block) {
198
    $query->values($block);
199
  }
200
  $query->execute();
201

    
202
  // Insert default pre-defined node types into the database. For a complete
203
  // list of available node type attributes, refer to the node type API
204
  // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info.
205
  $types = array(
206
    array(
207
      'type' => 'page',
208
      'name' => st('Basic page'),
209
      'base' => 'node_content',
210
      'description' => st("Use <em>basic pages</em> for your static content, such as an 'About us' page."),
211
      'custom' => 1,
212
      'modified' => 1,
213
      'locked' => 0,
214
    ),
215
    array(
216
      'type' => 'article',
217
      'name' => st('Article'),
218
      'base' => 'node_content',
219
      'description' => st('Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.'),
220
      'custom' => 1,
221
      'modified' => 1,
222
      'locked' => 0,
223
    ),
224
  );
225

    
226
  foreach ($types as $type) {
227
    $type = node_type_set_defaults($type);
228
    node_type_save($type);
229
    node_add_body_field($type);
230
  }
231

    
232
  // Insert default pre-defined RDF mapping into the database.
233
  $rdf_mappings = array(
234
    array(
235
      'type' => 'node',
236
      'bundle' => 'page',
237
      'mapping' => array(
238
        'rdftype' => array('foaf:Document'),
239
      ),
240
    ),
241
    array(
242
      'type' => 'node',
243
      'bundle' => 'article',
244
      'mapping' => array(
245
        'field_image' => array(
246
          'predicates' => array('og:image', 'rdfs:seeAlso'),
247
          'type' => 'rel',
248
        ),
249
        'field_tags' => array(
250
          'predicates' => array('dc:subject'),
251
          'type' => 'rel',
252
        ),
253
      ),
254
    ),
255
  );
256
  foreach ($rdf_mappings as $rdf_mapping) {
257
    rdf_mapping_save($rdf_mapping);
258
  }
259

    
260
  // Default "Basic page" to not be promoted and have comments disabled.
261
  variable_set('node_options_page', array('status'));
262
  variable_set('comment_page', COMMENT_NODE_HIDDEN);
263

    
264
  // Don't display date and author information for "Basic page" nodes by default.
265
  variable_set('node_submitted_page', FALSE);
266

    
267
  // Enable user picture support and set the default to a square thumbnail option.
268
  variable_set('user_pictures', '1');
269
  variable_set('user_picture_dimensions', '1024x1024');
270
  variable_set('user_picture_file_size', '800');
271
  variable_set('user_picture_style', 'thumbnail');
272

    
273
  // Allow visitor account creation with administrative approval.
274
  variable_set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
275

    
276
  // Create a default vocabulary named "Tags", enabled for the 'article' content type.
277
  $description = st('Use tags to group articles on similar topics into categories.');
278
  $vocabulary = (object) array(
279
    'name' => st('Tags'),
280
    'description' => $description,
281
    'machine_name' => 'tags',
282
  );
283
  taxonomy_vocabulary_save($vocabulary);
284

    
285
  $field = array(
286
    'field_name' => 'field_' . $vocabulary->machine_name,
287
    'type' => 'taxonomy_term_reference',
288
    // Set cardinality to unlimited for tagging.
289
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
290
    'settings' => array(
291
      'allowed_values' => array(
292
        array(
293
          'vocabulary' => $vocabulary->machine_name,
294
          'parent' => 0,
295
        ),
296
      ),
297
    ),
298
  );
299
  field_create_field($field);
300

    
301
  $help = st('Enter a comma-separated list of words to describe your content.');
302
  $instance = array(
303
    'field_name' => 'field_' . $vocabulary->machine_name,
304
    'entity_type' => 'node',
305
    'label' => 'Tags',
306
    'bundle' => 'article',
307
    'description' => $help,
308
    'widget' => array(
309
      'type' => 'taxonomy_autocomplete',
310
      'weight' => -4,
311
    ),
312
    'display' => array(
313
      'default' => array(
314
        'type' => 'taxonomy_term_reference_link',
315
        'weight' => 10,
316
      ),
317
      'teaser' => array(
318
        'type' => 'taxonomy_term_reference_link',
319
        'weight' => 10,
320
      ),
321
    ),
322
  );
323
  field_create_instance($instance);
324

    
325

    
326
  // Create an image field named "Image", enabled for the 'article' content type.
327
  // Many of the following values will be defaulted, they're included here as an illustrative examples.
328
  // See http://api.drupal.org/api/function/field_create_field/7
329

    
330
  $field = array(
331
    'field_name' => 'field_image',
332
    'type' => 'image',
333
    'cardinality' => 1,
334
    'locked' => FALSE,
335
    'indexes' => array('fid' => array('fid')),
336
    'settings' => array(
337
      'uri_scheme' => 'public',
338
      'default_image' => FALSE,
339
    ),
340
    'storage' => array(
341
      'type' => 'field_sql_storage',
342
      'settings' => array(),
343
    ),
344
  );
345
  field_create_field($field);
346

    
347

    
348
  // Many of the following values will be defaulted, they're included here as an illustrative examples.
349
  // See http://api.drupal.org/api/function/field_create_instance/7
350
  $instance = array(
351
    'field_name' => 'field_image',
352
    'entity_type' => 'node',
353
    'label' => 'Image',
354
    'bundle' => 'article',
355
    'description' => st('Upload an image to go with this article.'),
356
    'required' => FALSE,
357

    
358
    'settings' => array(
359
      'file_directory' => 'field/image',
360
      'file_extensions' => 'png gif jpg jpeg',
361
      'max_filesize' => '',
362
      'max_resolution' => '',
363
      'min_resolution' => '',
364
      'alt_field' => TRUE,
365
      'title_field' => '',
366
    ),
367

    
368
    'widget' => array(
369
      'type' => 'image_image',
370
      'settings' => array(
371
        'progress_indicator' => 'throbber',
372
        'preview_image_style' => 'thumbnail',
373
      ),
374
      'weight' => -1,
375
    ),
376

    
377
    'display' => array(
378
      'default' => array(
379
        'label' => 'hidden',
380
        'type' => 'image',
381
        'settings' => array('image_style' => 'large', 'image_link' => ''),
382
        'weight' => -1,
383
      ),
384
      'teaser' => array(
385
        'label' => 'hidden',
386
        'type' => 'image',
387
        'settings' => array('image_style' => 'medium', 'image_link' => 'content'),
388
        'weight' => -1,
389
      ),
390
    ),
391
  );
392
  field_create_instance($instance);
393

    
394
  // Enable default permissions for system roles.
395
  $filtered_html_permission = filter_permission_name($filtered_html_format);
396
  user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content', 'access comments', $filtered_html_permission));
397
  user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access content', 'access comments', 'post comments', 'skip comment approval', $filtered_html_permission));
398

    
399
  // Create a default role for site administrators, with all available permissions assigned.
400
  $admin_role = new stdClass();
401
  $admin_role->name = 'administrator';
402
  $admin_role->weight = 2;
403
  user_role_save($admin_role);
404
  user_role_grant_permissions($admin_role->rid, array_keys(module_invoke_all('permission')));
405
  // Set this as the administrator role.
406
  variable_set('user_admin_role', $admin_role->rid);
407

    
408
  // Assign user 1 the "administrator" role.
409
  db_insert('users_roles')
410
    ->fields(array('uid' => 1, 'rid' => $admin_role->rid))
411
    ->execute();
412

    
413
  // Create a Home link in the main menu.
414
  $item = array(
415
    'link_title' => st('Home'),
416
    'link_path' => '<front>',
417
    'menu_name' => 'main-menu',
418
  );
419
  menu_link_save($item);
420

    
421
  // Update the menu router information.
422
  menu_rebuild();
423

    
424
  // Enable the admin theme.
425
  db_update('system')
426
    ->fields(array('status' => 1))
427
    ->condition('type', 'theme')
428
    ->condition('name', 'seven')
429
    ->execute();
430
  variable_set('admin_theme', 'seven');
431
  variable_set('node_admin_theme', '1');
432
}