-
Notifications
You must be signed in to change notification settings - Fork 16
/
deims.install
525 lines (468 loc) · 16 KB
/
deims.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
<?php
/**
* @file
* Install, update and uninstall functions for the DEIMS installation profile.
*/
define('DEIMS_DEFAULT_THEME', 'deims_theme');
define('DEIMS_ADMIN_THEME', 'deims_admin');
/**
* Implements hook_install().
*/
function deims_install() {
/*$modules = array();
foreach (system_rebuild_module_data() as $module) {
if (!empty($module->status)) {
$modules[$module->name] = $module->sort;
}
}
asort($modules);
// Run the install task for each enabled module.
foreach (array_keys($modules) as $module) {
module_invoke('deims', 'install_' . $module);
}*/
deims_install_filter();
deims_install_user();
deims_install_block();
deims_install_system();
deims_install_taxonomy();
// Contrib modules
deims_install_admin_menu();
deims_install_admin_select();
deims_install_chosen();
deims_install_custom_breadcrumbs();
deims_install_schema();
deims_install_workbench_access();
variable_set('menu_rebuild_needed', TRUE);
// Clear any normal messages from being displayed.
drupal_get_messages('status');
}
/**
* Profile install tasks for the block module.
*/
function deims_install_block() {
$blocks = array(
array(
'module' => 'system',
'delta' => 'help',
'theme' => DEIMS_DEFAULT_THEME,
'status' => 1,
'weight' => -22,
'region' => 'content',
'pages' => '',
'cache' => -1,
),
array(
'module' => 'workbench',
'delta' => 'block',
'theme' => DEIMS_DEFAULT_THEME,
'status' => 1,
'weight' => -21,
'region' => 'content',
'pages' => '',
'cache' => -1,
),
array(
'module' => 'system',
'delta' => 'main',
'theme' => DEIMS_DEFAULT_THEME,
'status' => 1,
'weight' => -20,
'region' => 'content',
'pages' => '',
'cache' => -1,
),
array(
'module' => 'system',
'delta' => 'help',
'theme' => DEIMS_ADMIN_THEME,
'status' => 1,
'weight' => -22,
'region' => 'content',
'pages' => '',
'cache' => -1,
),
array(
'module' => 'workbench',
'delta' => 'block',
'theme' => DEIMS_ADMIN_THEME,
'status' => 1,
'weight' => -21,
'region' => 'content',
'pages' => '',
'cache' => -1,
),
array(
'module' => 'system',
'delta' => 'main',
'theme' => DEIMS_ADMIN_THEME,
'status' => 1,
'weight' => -20,
'region' => 'content',
'pages' => '',
'cache' => -1,
),
);
$query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
foreach ($blocks as $block) {
$query->values($block);
}
$query->execute();
}
/**
* Profile install tasks for the filter module.
*/
function deims_install_filter() {
$filtered_html_format = array(
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
'filters' => array(
// URL filter.
'filter_url' => array(
'weight' => 0,
'status' => 1,
),
// HTML filter.
'filter_html' => array(
'weight' => 1,
'status' => 1,
),
// Line break filter.
'filter_autop' => array(
'weight' => 2,
'status' => 1,
),
// HTML corrector filter.
'filter_htmlcorrector' => array(
'weight' => 10,
'status' => 1,
),
// Empty paragraph killer filter.
'emptyparagraphkiller' => array(
'weight' => 15,
'status' => 1,
),
),
);
$filtered_html_format = (object) $filtered_html_format;
filter_format_save($filtered_html_format);
$full_html_format = array(
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 1,
'filters' => array(
// URL filter.
'filter_url' => array(
'weight' => 0,
'status' => 1,
),
// Line break filter.
'filter_autop' => array(
'weight' => 1,
'status' => 1,
),
// HTML corrector filter.
'filter_htmlcorrector' => array(
'weight' => 10,
'status' => 1,
),
// Empty paragraph killer filter.
'emptyparagraphkiller' => array(
'weight' => 15,
'status' => 1,
),
),
);
$full_html_format = (object) $full_html_format;
filter_format_save($full_html_format);
}
/**
* Profile install tasks for the system module.
*/
function deims_install_system() {
// Enable the default and admin themes.
theme_enable(array(DEIMS_DEFAULT_THEME, DEIMS_ADMIN_THEME));
variable_set('theme_default', DEIMS_DEFAULT_THEME);
variable_set('admin_theme', DEIMS_ADMIN_THEME);
variable_set('node_admin_theme', '1');
// Disable Bartik
//theme_disable(array('bartik'));
// Set settings for the theme including color scheme.
$form_state = array();
form_load_include($form_state, 'inc', 'system', 'system.admin');
$form_state['build_info']['args'][0] = DEIMS_DEFAULT_THEME;
$form_state['values']['scheme'] = 'deepblue';
drupal_form_submit('system_theme_settings', $form_state);
// Set up the ISO 8601 date format.
variable_set('date_format_iso_8601', 'Y-m-d\TH:i:sO');
}
/**
* Profile install tasks for the user module.
*/
function deims_install_user() {
// Enable user picture support and set the default to a square thumbnail option.
variable_set('user_pictures', '1');
variable_set('user_picture_dimensions', '1024x1024');
variable_set('user_picture_file_size', '800');
variable_set('user_picture_style', 'thumbnail');
// Do not allow user account creation by default.
variable_set('user_register', USER_REGISTER_ADMINISTRATORS_ONLY);
// Enable default permissions for system roles.
$format = filter_format_load('full_html');
$filtered_html_permission = filter_permission_name($format);
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content', $filtered_html_permission));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access content', $filtered_html_permission));
// Create a default role for site administrators, with all available permissions assigned.
$admin_role = new stdClass();
$admin_role->name = 'administrator';
$admin_role->weight = 5;
user_role_save($admin_role);
user_role_grant_permissions($admin_role->rid, array_keys(module_invoke_all('permission')));
// Set this as the administrator role.
variable_set('user_admin_role', $admin_role->rid);
$account = user_load(1);
$account->roles[$admin_role->rid] = $admin_role->name;
$account->data['admin_select'] = 'admin_menu';
user_save($account);
// Create the DEIMS roles.
$role = new stdClass();
$role->name = 'content contributor';
$role->weight = 2;
user_role_save($role);
$role = new stdClass();
$role->name = 'data contributor';
$role->weight = 3;
user_role_save($role);
$role = new stdClass();
$role->name = 'information manager';
$role->weight = 4;
user_role_save($role);
}
/**
* Profile install tasks for the admin_select module.
*/
function deims_install_admin_select() {
$admin_role = user_role_load_by_name('administrator');
variable_set('admin_select_defaults', array(
$admin_role->rid => array('admin_select_default' => 'admin_menu', 'weight' => -2),
DRUPAL_AUTHENTICATED_RID => array('admin_select_default' => 'toolbar', 'weight' => -1),
));
}
/**
* Profile install tasks for the admin_menu module.
*/
function deims_install_admin_menu() {
variable_set('admin_menu_components', array(
'admin_menu.icon' => TRUE,
'admin_menu.menu' => TRUE,
'admin_menu.search' => TRUE,
'admin_menu.users' => FALSE,
'admin_menu.account' => TRUE,
'shortcut.links' => TRUE,
));
}
/**
* Profile install tasks for the schema module.
*/
function deims_install_schema() {
variable_set('schema_suppress_type_warnings', TRUE);
variable_set('schema_status_report', FALSE);
}
/**
* Profile install tasks for the workbench_access module.
*/
function deims_install_workbench_access() {
variable_set('workbench_access', 'taxonomy');
variable_set('workbench_access_taxonomy', array('section' => 'section'));
variable_set('workbench_access_custom_form', 0);
}
/**
* Porfile install for custom breadcrumbs.
*/
function deims_install_custom_breadcrumbs() {
$custom_breadcrumbs = array(
array(
'name' => 'Node: Data set',
'titles' => 'Data',
'paths' => 'data',
'visibility_php' => '',
'node_type' => 'data_set',
'language' => '',
),
array(
'name' => 'Node: Data source',
'titles' => 'Data' . "\r\n" . '[node:source-data-set]',
'paths' => 'data' . "\r\n" . '[node:source-data-set:url:path]',
'visibility_php' => '',
'node_type' => 'data_source',
'language' => '',
),
array(
'name' => 'Node: Article',
'titles' => '[node:field_section]',
'paths' => '[node:field-section:url:path]',
'visibility_php' => '',
'node_type' => 'article',
'language' => '',
),
array(
'name' => 'Node: Research site',
'titles' => 'About' . "\r\n" . 'Research Sites',
'paths' => 'about' . "\r\n" . 'about/sites',
'visibility_php' => '',
'node_type' => 'research_site',
'language' => '',
),
);
$query = db_insert('custom_breadcrumb')->fields(array(
'name',
'titles',
'paths',
'visibility_php',
'node_type',
'language',
));
foreach ($custom_breadcrumbs as $custom_breadcrumb) {
$query->values($custom_breadcrumb);
}
$query->execute();
}
/**
* Profile install for the chosen module.
*/
function deims_install_chosen() {
variable_set('chosen_minimum_width', 250);
variable_set('chosen_jquery_selector', 'select:visible, .filefield-source-attach select, .field-widget-addressfield-standard select');
}
/**
* Profile install for taxonomy.
*/
function deims_install_taxonomy() {
$path = drupal_get_path('profile', 'deims') . '/exports/taxonomy-core-areas.csv';
$file = new SplFileObject($path);
while (!$file->eof()) {
$term = new stdClass();
list(
$term->name,
$term->vocabulary_machine_name,
$term->description,
$term->format,
$term->weight,
//(int) $term->parent,
) = $file->fgetcsv();
if (!empty($term->vocabulary_machine_name)) {
taxonomy_term_save($term);
}
}
}
/**
* Implements hook_form_FORM_ID_alter() for install_configure_form().
*
* Allows the profile to alter the site configuration form.
*/
function deims_form_install_configure_form_alter(&$form, $form_state) {
// Pre-populate the site name with the server name.
$form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME'];
// Set a default country so we can benefit from it on Address Fields.
$form['server_settings']['site_default_country']['#default_value'] = 'US';
// Disable update notifications by default.
$form['update_notifications']['update_status_module']['#default_value'] = array();
// Add an environment selector.
// @todo Add a helpful #description to this element.
$form['site_information']['environment'] = array(
'#type' => 'select',
'#title' => t('Environment'),
'#options' => array(
'development' => st('Development'),
'production' => st('Production'),
),
'#default_value' => variable_get('environment', 'development'),
'#required' => TRUE,
);
$form['#submit'][] = 'deims_form_install_configure_form_submit';
}
function deims_form_install_configure_form_submit($form, &$form_state) {
variable_set('environment', $form_state['values']['environment']);
module_invoke_all('environment_switch', $form_state['values']['environment'], NULL);
}
/**
* Implements hook_install_tasks().
*/
function deims_install_tasks(&$install_state) {
$tasks['deims_welcome_page'] = array(
'display_name' => st('A helpful welcome page'),
'type' => 'normal',
);
$tasks['deims_configure_eml_form'] = array(
'display_name' => st('EML configuration'),
'type' => 'form',
);
$tasks['deims_select_enhancements_form'] = array(
'display_name' => st('Optional DEIMS features'),
'type' => 'form',
);
return $tasks;
}
function deims_welcome_page() {
global $user;
$values = array(
'type' => 'page',
'uid' => $user->uid,
'status' => 1,
'comment' => 1,
'promote' => 1,
);
$entity = entity_create('node', $values);
$ewrapper = entity_metadata_wrapper('node', $entity);
$ewrapper->title->set('Welcome to the Drupal Ecological Information Management System!');
$my_body_content = 'Hello There! Joining the ranks of scientists that use <a href="http://drupal.org/project/deims"> DEIMS</a>? You will manage data, publications, projects, locations, metadata, documents, photos and relevant information.
<p>DEIMS enables storing, editing and sharing data and information about your biological and ecological research. Your team work will be findable, versioned and compliant with common standards (ISO, Google and others).</p>
<h2>Getting Started</h2>
DEIMS is based on <a href="https://drupal.org">Drupal</a> content management system. There is a wealth of information and documentation about Drupal on the web. If you are confortable using a Drupal based website, DEIMS is second nature to you. But Drupal experience is not required to use DEIMS. We have prepared for you <a href="https://docs.google.com/document/d/1zf5O56_WjMTRngSzY7vuDIT-lMLS0DljoGBqiAM5lAw/edit?usp=sharing">documentation specific to DEIMS</a>. How to create a data-set, how to add files, photos, publications. All of it.
<h2>Maintaining DEIMS</h2>
Your DEIMS administrator will leverage the <a href="https://groups.google.com/forum/#!forum/deims">helper notices </a> posted in the DEIMS support group, as well as tips and tricks found in the above cited <em>Book of DEIMS</em>. What are the first things you would want to do? Well, first you want to customize the look-and-feel to suit your group -- head to the <a href="/admin/appearance/settings/deims_theme">Theme administration pages</a> to add logos, color-schemas, fonts and the likes.
<h2>Adding Content</h2>
You will need to start populating your DEIMS site; adding dataset description, personel profiles, photos, etc. For example, you may want to show a personnel directory (your group!), one of my favs starting places. If yours is a large directory, consider using migrate tools to import in bulk. Likewise for other large number of assets. Otherwise, the user-friendly forms will help you creating your site.<p>One more thing: Do not forget to demote this page from your DEIMS frontpage, or to unpublish or, (gasp), delete it.';
$ewrapper->body->set(array('value' => $my_body_content, 'format' => 'full_html', 'summary' => $my_body_content));
$my_date = new DateTime('May 4, 2016');
$entity->field_my_date[LANGUAGE_NONE][0] = array(
'value' => date_format($my_date, 'Y-m-d'),
'timezone' => 'UTC',
'timezone_db' => 'UTC',
);
$ewrapper->save();
}
function deims_configure_eml_form($form, &$form_state, &$install_state) {
form_load_include($form_state, 'inc', 'eml', 'eml.admin');
$form = eml_settings_form($form, $form_state);
$form['tokens']['#access'] = FALSE;
$form['pasta']['eml_paste_base_url']['#access'] = FALSE;
$form['pasta']['tokens']['#access'] = FALSE;
return $form;
}
function deims_select_enhancements_form($form, &$form_state, &$install_state) {
$form['modules'] = array(
'#type' => 'checkboxes',
'#title' => t('Enable optional DEIMS enhancement modules'),
'#options' => array(),
);
$modules = system_rebuild_module_data();
foreach ($modules as $module) {
if (empty($module->status) && $module->info['package'] == 'DEIMS Enhancements') {
$form['modules']['#options'][$module->name] = check_plain($module->info['name']);
$form['modules'][$module->name]['#description'] = check_plain($module->info['description']);
}
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => st('Save and continue'),
'#weight' => 15,
);
return $form;
}
function deims_select_enhancements_form_submit($form, &$form_state) {
if ($modules = array_keys(array_filter($form_state['values']['modules']))) {
module_enable($modules);
}
}