-
Notifications
You must be signed in to change notification settings - Fork 0
/
soe_profile.post_update.php
122 lines (110 loc) · 3.49 KB
/
soe_profile.post_update.php
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
<?php
/**
* @file
* soe_profile.install
*/
use Drupal\block\Entity\Block;
use Drupal\Core\Serialization\Yaml;
/**
* Implements hook_removed_post_updates().
*/
function soe_profile_removed_post_updates() {
return [
'soe_profile_post_update_8101' => '8.x-2.0',
'soe_profile_post_update_8102' => '8.x-2.0',
'soe_profile_post_update_8103' => '8.x-2.0',
'soe_profile_post_update_8104' => '8.x-2.0',
'soe_profile_post_update_8200_uuids' => '8.x-2.10',
];
}
/**
* Create default past event and event series node pages if content exists.
*/
function soe_profile_post_update_8201_search(){
\Drupal::service('module_installer')->uninstall(['search']);
}
/**
* Add the main anchor block to the search page.
*/
function soe_profile_post_update_8202() {
$theme_name = \Drupal::config('system.theme')->get('default');
if (!in_array($theme_name, [
'soe_basic',
'stanford_basic',
'minimally_branded_subtheme',
])) {
Block::create([
'id' => "{$theme_name}_main_anchor",
'theme' => $theme_name,
'region' => 'content',
'weight' => -10,
'plugin' => 'jumpstart_ui_skipnav_main_anchor',
'settings' => [
'id' => 'jumpstart_ui_skipnav_main_anchor',
'label' => 'Main content anchor target',
'label_display' => 0,
],
'visibility' => [
'request_path' => [
'id' => 'request_path',
'negate' => FALSE,
'pages' => '/search',
],
],
])->save();
}
}
/**
* Update field storage definitions.
*/
function soe_profile_post_update_update_field_defs() {
$um = \Drupal::entityDefinitionUpdateManager();
foreach ($um->getChangeList() as $entity_type => $changes) {
if (isset($changes['field_storage_definitions'])) {
foreach ($changes['field_storage_definitions'] as $field_name => $status) {
$um->updateFieldStorageDefinition($um->getFieldStorageDefinition($field_name, $entity_type));
}
}
}
}
/**
* Enable samlauth.
*/
function soe_profile_post_update_samlauth() {
if (\Drupal::moduleHandler()->moduleExists('stanford_samlauth')) {
return;
}
$ignore_settings = \Drupal::configFactory()
->getEditable('config_ignore.settings');
$ignored = $ignore_settings->get('ignored_config_entities');
$ignored[] = 'samlauth.authentication:map_users_roles';
$ignore_settings->set('ignored_config_entities', $ignored)->save();
\Drupal::service('module_installer')->install(['stanford_samlauth']);
}
/**
* Create site org vocab and terms.
*/
function soe_profile_post_update_site_orgs() {
$vocab_storage = \Drupal::entityTypeManager()
->getStorage('taxonomy_vocabulary');
if (!$vocab_storage->load('site_owner_orgs')) {
$vocab_storage->create([
'uuid' => '0611ae1d-2ab4-46c3-9cc8-2259355f0852',
'vid' => 'site_owner_orgs',
'name' => 'Site Owner Orgs',
])->save();
$profile_name = \Drupal::config('core.extension')->get('profile');
$profile_path = \Drupal::service('extension.list.profile')
->getPath($profile_name);
/** @var \Drupal\default_content\Normalizer\ContentEntityNormalizer $importer */
$normalizer = \Drupal::service('default_content.content_entity_normalizer');
$files = \Drupal::service('default_content.content_file_storage')
->scan("$profile_path/content/taxonomy_term");
foreach ($files as $file) {
$term = Yaml::decode(file_get_contents($file->uri));
if ($term['_meta']['bundle'] == 'site_owner_orgs') {
$normalizer->denormalize($term)->save();
}
}
}
}