forked from relaxedws/drupal-relaxed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
relaxed.install
66 lines (61 loc) · 2.46 KB
/
relaxed.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
<?php
use Drupal\user\Entity\Role;
/**
* Implements hook_install().
*/
function relaxed_install() {
// Demonstrate best security practice and create a separate role with the
// only permissions needed to perform content replication.
$rid = 'replicator';
$replicator_role = Role::load($rid);
if (empty($replicator_role)) {
Role::create([
'id' => $rid,
'label' => 'Replicator',
'weight' => 0,
'is_admin' => 0,
'permissions' => [
'perform push replication',
'administer users',
'administer workspaces'
],
])->save();
}
// Keep this just for compatibility with Drupal 8.1.x.
// @todo Remove when we decide to not support Drupal 8.1.x.
$module_handler = \Drupal::moduleHandler();
// Merge 'resource' settings from relaxed module with 'resource' settings from rest module,
// these settings are not loaded if added to /config/install/rest.settings.yml.
// @todo {@link https://www.drupal.org/node/2599862 Figure out a better way to do this.}
$relaxed_resource_config = \Drupal::config('relaxed.settings')->get('resources');
$rest_config = \Drupal::configFactory()->getEditable('rest.settings');
$rest_resource_config = $rest_config->get('resources');
// The rest module define settings for the node entity type but doesn't
// declare a dependency on node. This is causing trouble in some of our tests
// for some reason. So we remove those settings if the node modules is not
// enabled.
if (!$module_handler->moduleExists('node')) {
unset($rest_resource_config['entity:node']);
}
if (is_array($rest_resource_config)) {
$rest_config->set('resources', array_merge($rest_resource_config, $relaxed_resource_config))->save();
}
}
/**
* Implements hook_uninstall().
*/
function relaxed_uninstall() {
// Keep this just for compatibility with Drupal 8.1.x.
// @todo Remove when we decide to not support Drupal 8.1.x.
// Remove 'resource' settings defined by RELAXed Web Services module from
// 'resource' settings defined by RESTful Web Services module.
$relaxed_resource_config = \Drupal::config('relaxed.settings')->get('resources');
$rest_config = \Drupal::configFactory()->getEditable('rest.settings');
$rest_resource_config = $rest_config->get('resources');
foreach ($relaxed_resource_config as $key => $item) {
if (isset($rest_resource_config[$key])) {
unset($rest_resource_config[$key]);
}
}
$rest_config->set('resources', $rest_resource_config)->save();
}