-
Notifications
You must be signed in to change notification settings - Fork 0
/
dkan_workflow.install
80 lines (63 loc) · 2.33 KB
/
dkan_workflow.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
<?php
/**
* @file
* Installation procedures for dkan_workflow.
*/
/**
* Implements hook_install().
*/
function dkan_workflow_install() {
$item = array(
'link_path' => 'admin/workbench',
'link_title' => 'My Workbench',
'menu_name' => 'menu-command-center-menu',
'weight' => -50,
'expanded' => 0,
);
$item_id = menu_link_save($item);
dkan_workflow_revert_views();
}
/**
* Implements hook_enable().
*/
function dkan_workflow_enable() {
// Enable moderation for dkan_workflow enabled content types upon install. This
// config is kept persistant using the hook_strongarm_alter().
// Default dkan content types with moderation.
$dkan_workflow_content_types = array('dataset', 'resource', 'feedback');
foreach ($dkan_workflow_content_types as $type) {
$var_name = 'node_options_' . $type;
$node_options = variable_get($var_name, array());
$node_options = (array_key_exists($var_name, $node_options) && is_array($node_options[$var_name]->value)) ?
$node_options[$var_name]->value :
$node_options;
// Remove status if set;
$node_options = array_diff($node_options, array('status'));
// Add moderation and revision if needed.
$node_options = array_values(array_unique(array_merge($node_options, array('moderation', 'revision')), SORT_REGULAR));
variable_set($var_name, $node_options);
}
dkan_workflow_revert_views();
variable_set('dkan_workflow_content_types', $dkan_workflow_content_types);
// Add dkan workflow roles to roleassign config.
$roleassign_roles = variable_get('roleassign_roles', array());
$roles_rids = array_flip(user_roles());
$add_roles = array('Workflow Contributor', 'Workflow Moderator', 'Workflow Supervisor');
foreach($add_roles as $role) {
$roleassign_roles[$roles_rids[$role]] = (string) $roles_rids[$role];
}
variable_set('roleassign_roles', $roleassign_roles);
}
/**
* Implements hook_disable().
*/
function dkan_workflow_disable() {
// Remove workflow roles from roleassign_roles variable
$roleassign_roles = variable_get('roleassign_roles', array());
$roles_rids = array_flip(user_roles());
$remove_roles = array('Workflow Contributor', 'Workflow Moderator', 'Workflow Supervisor');
foreach($remove_roles as $role) {
unset($roleassign_roles[$roles_rids[$role]]);
}
variable_set('roleassign_roles', $roleassign_roles);
}