-
Notifications
You must be signed in to change notification settings - Fork 2
/
tide_authenticated_content.install
83 lines (78 loc) · 2.31 KB
/
tide_authenticated_content.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
<?php
/**
* @file
* Tide Authenticated Content module install file.
*/
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\NodeType;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\paragraphs\Entity\ParagraphsType;
use Drupal\user\Entity\Role;
/**
* Implements hook_install().
*/
function tide_authenticated_content_install() {
if (!\Drupal::service('config.installer')->isSyncing()) {
$module_installer = \Drupal::service('module_installer');
$module_installer->install([
'key',
'jwt',
'jwt_auth_consumer',
'jwt_auth_issuer',
'permissions_by_term',
'rest',
]);
}
}
/**
* Implements hook_uninstall().
*/
function tide_authenticated_content_uninstall() {
// Remove permissions on tide_authenticated_content to Approver and Editor.
$roles = ['approver', 'editor'];
$permissions = [
'create terms in authenticated_content',
'create terms in authenticated_content',
];
foreach ($roles as $role_name) {
$role = Role::load($role_name);
if ($role) {
foreach ($permissions as $permission) {
$role->revokePermission($permission);
}
$role->save();
}
}
// Clean up paragraphs.
$paragraph_query = \Drupal::entityTypeManager()
->getStorage('paragraph')
->getQuery();
$results = $paragraph_query->condition('type', 'user_authentication_block')
->accessCheck(FALSE)
->execute();
if ($results) {
$paragraphs = Paragraph::loadMultiple($results);
\Drupal::entityTypeManager()->getStorage('paragraph')->delete($paragraphs);
}
if ($paragraph_type_entity = ParagraphsType::load('user_authentication_block')) {
\Drupal::entityTypeManager()
->getStorage('paragraphs_type')
->delete([$paragraph_type_entity]);
}
$node_types = NodeType::loadMultiple();
if ($node_types) {
foreach ($node_types as $node_type => $details) {
$node_fields = \Drupal::service('entity_field.manager')
->getFieldDefinitions('node', $node_type);
if (isset($node_fields['field_authenticated_content'])) {
FieldConfig::loadByName('node', $node_type, 'field_authenticated_content')
->delete();
}
}
}
// Delete tide_authenticated_content related rows.
\Drupal::database()
->delete('node_access')
->condition('realm', 'tide_authenticated_content')
->execute();
}