-
Notifications
You must be signed in to change notification settings - Fork 3
/
govcms.install
106 lines (91 loc) · 2.7 KB
/
govcms.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
<?php
/**
* @file
* Install, update and uninstall hooks for the govCMS profile.
*/
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
use Drupal\shortcut\Entity\Shortcut;
/**
* Define a default theme constant.
*/
define('GOVCMS_DEFAULT_THEME', 'govcmsui');
/**
* Define the admin theme.
*/
define('GOVCMS_DEFAULT_ADMIN_THEME', 'adminimal_theme');
/**
* Implements hook_install().
*
* Perform actions to set up the site for govCMS Profile.
*
* @see system_install()
*/
function govcms_install() {
// Restrict user registration to admin role creation.
$user_settings = \Drupal::configFactory()->getEditable('user.settings');
$user_settings->set('register', USER_REGISTER_ADMINISTRATORS_ONLY)->save(TRUE);
// Allow all users to use search.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['search content']);
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['search content']);
// Allow authenticated users to use shortcuts.
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access shortcuts']);
// Populate the default shortcut set.
Shortcut::create(
[
'shortcut_set' => 'default',
'title' => t('Add content'),
'weight' => 1,
'link' => ['uri' => 'internal:/node/add'],
]
)->save();
// Don't do anything else during config sync.
if (\Drupal::isConfigSyncing()) {
return;
}
// Set front page to "node".
\Drupal::configFactory()
->getEditable('system.site')
->set('page.front', '/node')
->save(TRUE);
// Set the default and admin theme.
\Drupal::configFactory()
->getEditable('system.theme')
->set('default', GOVCMS_DEFAULT_THEME)
->set('admin', GOVCMS_DEFAULT_ADMIN_THEME)
->save(TRUE);
// Enable the admin theme.
\Drupal::configFactory()
->getEditable('node.settings')
->set('use_admin_theme', TRUE)
->save(TRUE);
// Set the path to the logo, favicon and README file based on install directory.
$govcms_path = drupal_get_path('profile', 'govcms');
\Drupal::configFactory()
->getEditable('system.theme.global')
->set('logo', [
'path' => $govcms_path . '/logo.svg',
'url' => '',
'use_default' => FALSE,
])
->set('favicon', [
'mimetype' => 'image/vnd.microsoft.icon',
'path' => $govcms_path . '/favicon.ico',
'url' => '',
'use_default' => FALSE,
])
->save(TRUE);
}
/**
* Implements hook_install_tasks().
*/
function govcms_install_tasks(&$install_state) {
$tasks = [];
// Install optional modules.
$tasks['govcms_install_optional'] = [
'display_name' => t('Install optional modules'),
'type' => 'form',
'function' => 'Drupal\govcms\Installer\Form\optionalForm',
];
return $tasks;
}