This repository has been archived by the owner on Oct 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stanford_mrc.install
207 lines (179 loc) · 5.63 KB
/
stanford_mrc.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
<?php
/**
* @file
* stanford_mrc.install
*/
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
use Drupal\shortcut\Entity\Shortcut;
use Drupal\Core\Config\FileStorage;
/**
* Implements hook_install().
*/
function stanford_mrc_install() {
// Assign user 1 the "administrator" role.
$user = User::load(1);
$user->roles[] = 'administrator';
$user->save();
// We install some menu links, so we have to rebuild the router, to ensure the
// menu links are valid.
\Drupal::service('router.builder')->rebuildIfNeeded();
// Allow authenticated users to use shortcuts.
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access shortcuts']);
// Populate the default shortcut set.
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('Add content'),
'weight' => -20,
'link' => ['uri' => 'internal:/node/add'],
]);
$shortcut->save();
$shortcut = Shortcut::create([
'shortcut_set' => 'default',
'title' => t('All content'),
'weight' => -19,
'link' => ['uri' => 'internal:/admin/content'],
]);
$shortcut->save();
// Allow all users to use search.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['search content']);
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['search content']);
}
/**
* Run after installation to force the configs to re-save.
*/
function stanford_mrc_after_install() {
stanford_mrc_update_configs(TRUE, 'all');
}
/**
* Read from the file and re-save the configuration entities.
*
* This does not create field tables, that must be done before updating the
* configurations for the field. Simply create the field and instance, then
* call this function to revert the field settings. see
* https://www.drupal8.ovh/en/tutoriels/283/create-a-field-a-node-entity-programmatically-on-drupal-8
* for more information.
*
* @param bool $create_missing
* Create all missing configs in addition to the configs defined in $configs.
* @param array|string $configs
* Array of config names to update, string "all" to import all.
* @param string $path
* Path to the config files.
*/
function stanford_mrc_update_configs($create_missing = TRUE, $configs = [], $path = '') {
/** @var \Drupal\Core\Config\StorageInterface $active_storage */
$active_storage = \Drupal::service('config.storage');
if (empty($path)) {
$path = drupal_get_path('profile', 'stanford_mrc') . '/config/install';
}
$source = new FileStorage($path);
// If configs is all, grab all available configs in the profile.
if (is_string($configs) && $configs = 'all') {
$configs = $source->listAll();
}
elseif ($create_missing) {
// Merge missing configs with the specific configs.
$missing_configs = array_diff($source->listAll(), $active_storage->listAll());
$configs = array_unique(array_merge($configs, $missing_configs));
}
foreach ($configs as $config) {
// Write new configs.
if (!$active_storage->exists($config)) {
$active_storage->write($config, $source->read($config));
continue;
}
/** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
$config_factory = \Drupal::configFactory();
/** @var \Drupal\Core\Config\Config $config_entity */
$config_entity = $config_factory->getEditable($config);
// Read from config file.
$updated_config = $source->read($config);
unset($updated_config['uuid']);
$uuid = $config_entity->get('uuid');
// Make sure there is a UUID on the config.
if (empty($uuid)) {
$uuid_service = \Drupal::service('uuid');
$uuid = $uuid_service->generate();
}
$updated_config = ['uuid' => $uuid] + $updated_config;
// Set and save the data.
$config_entity->setData($updated_config);
$config_entity->save();
}
}
/**
* Creates missing text format.
*/
function stanford_mrc_update_8001() {
stanford_mrc_update_configs(TRUE, 'all');
}
/**
* Enables media and resets the text format.
*/
function stanford_mrc_update_8002() {
\Drupal::service('module_installer')->install(['mrc_media']);
stanford_mrc_update_configs(TRUE, 'all');
}
/**
* Resets the text format.
*/
function stanford_mrc_update_8003() {
stanford_mrc_update_configs(TRUE, 'all');
}
/**
* Enables new modules.
*/
function stanford_mrc_update_8004() {
\Drupal::service('theme_installer')->install(['math_research_center']);
stanford_mrc_update_configs(TRUE, 'all');
\Drupal::service('module_installer')->install([
'ui_patterns_ds',
'components',
'ui_patterns_views',
'ui_patterns_library',
'ui_patterns_layouts',
]);
}
/**
* Set blocks for math_research_center theme.
*/
function stanford_mrc_update_8005() {
\Drupal::service('module_installer')->install(['contextual']);
$theme_path = drupal_get_path('theme', 'math_research_center') . '/config/install';
stanford_mrc_update_configs(TRUE, 'all', $theme_path);
stanford_mrc_update_configs(TRUE, 'all');
}
/**
* Enables new modules.
*/
function stanford_mrc_update_8006() {
\Drupal::service('module_installer')->install([
'mrc_bricks_helper',
'mrc_display_modes',
'mrc_paragraphs_cta',
'mrc_paragraphs_postcard',
'mrc_page',
]);
stanford_mrc_update_configs(TRUE, 'all');
}
/**
* Enables mrc_helper module.
*/
function stanford_mrc_update_8007() {
\Drupal::service('module_installer')->install(['mrc_helper']);
}
/**
* Resets the text format settings & enables 2 module.
*/
function stanford_mrc_update_8008() {
$configs = [
'editor.editor.basic_html',
'filter.format.basic_html',
];
stanford_mrc_update_configs(TRUE, $configs);
\Drupal::service('module_installer')->install([
'mrc_ds_blocks',
'mrc_paragraphs_slideshow',
]);
}