forked from lemberg/draft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
draft.install
99 lines (88 loc) · 2.76 KB
/
draft.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
<?php
use Drupal\Core\Config\FileStorage;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
/**
* Implements hook_install_tasks().
*
* Performs tasks to set up the site for the Draft profile.
*
* @see hook_install_tasks()
*/
function draft_install_tasks(&$install_state) {
return [
'draft_set_role' => [],
'draft_config' => [],
];
}
/**
* Sets a role to a user for the Draft profile.
*/
function draft_set_role(&$install_state) {
// Assign user 1 the "administrator" role.
$role = Role::load('administrator');
if ($role) {
$user = User::load(1);
$user->addRole($role->id());
$user->save();
}
}
/**
* Prepares configs for the Draft profile.
*/
function draft_config(&$install_state) {
$config = _draft_read_develop_config_split();
_draft_prepare_develop_config_split_directory($config);
}
/**
* Installs Administration Links Access Filter module.
*/
function draft_update_8101(&$sandbox = NULL) {
\Drupal::service('module_installer')->install(['admin_links_access_filter']);
}
/**
* Installs Configuration Split module and Develop configuration split.
*/
function draft_update_8102(&$sandbox = NULL) {
if (!Drupal::moduleHandler()->moduleExists('config_split')) {
\Drupal::service('module_installer')->install(['config_split']);
$config = _draft_read_develop_config_split();
_draft_prepare_develop_config_split_directory($config);
/** @var \Drupal\Core\Config\CachedStorage $config_storage */
$config_storage = \Drupal::service('config.storage');
$config_storage->write('config_split.config_split.develop', $config);
}
}
/**
* Replace Administration Links Access Filter module with one bundled with Admin
* Toolbar module as of version 1.21.0.
*/
function draft_update_8103(&$sandbox = NULL) {
\Drupal::service('module_installer')->uninstall(['admin_links_access_filter']);
\Drupal::service('module_installer')->install(['admin_toolbar_links_access_filter']);
}
/**
* Reads Develop configuration split configuration data.
*
* @return array
* Develop configuration split configuration data.
*/
function _draft_read_develop_config_split() {
$config_path = drupal_get_path('profile', 'draft') . '/config/install';
$source = new FileStorage($config_path);
return $source->read('config_split.config_split.develop');
}
/**
* Prepares Develop configuration split export directory.
*
* @param array $config
* Develop configuration split configuration data.
*
* @return bool
* TRUE if Develop configuration split export directory exists and is
* writable, FALSE otherwise.
*/
function _draft_prepare_develop_config_split_directory(array $config) {
$directory = \Drupal::root() . '/' . $config['folder'];
return file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}