-
Notifications
You must be signed in to change notification settings - Fork 17
/
thunder.post_update.php
127 lines (111 loc) · 4.7 KB
/
thunder.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
123
124
125
126
127
<?php
/**
* @file
* Update functions for the thunder installation profile.
*/
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\ckeditor5\SmartDefaultSettings;
use Drupal\editor\Entity\Editor;
use Drupal\entity_browser\Entity\EntityBrowser;
use Drupal\user\Entity\Role;
/**
* Update to Thunder 7.
*/
function thunder_post_update_0001_upgrade_to_thunder7(array &$sandbox): string {
/** @var \Drupal\Core\Extension\ModuleInstallerInterface $moduleInstaller */
$moduleInstaller = \Drupal::service('module_installer');
$moduleInstaller->install([
'media_library_media_modify',
'gin_toolbar',
'jquery_ui',
'ckeditor5',
]);
/** @var \Drupal\update_helper\Updater $updater */
$updater = \Drupal::service('update_helper.updater');
$updater->executeUpdate('thunder', 'thunder_post_update_0001_upgrade_to_thunder7');
$permissions = [];
/** @var \Drupal\entity_browser\Entity\EntityBrowser $entity_browser */
foreach (EntityBrowser::loadMultiple() as $entity_browser) {
$permissions[] = 'access ' . $entity_browser->id() . ' entity browser pages';
}
foreach (Role::loadMultiple() as $role) {
foreach ($permissions as $permission) {
if ($role->hasPermission($permission)) {
$role->revokePermission($permission);
}
}
$role->save();
}
foreach (EntityFormDisplay::loadMultiple() as $entity_form_display) {
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($entity_form_display->getTargetEntityTypeId(), $entity_form_display->getTargetBundle());
foreach ($entity_form_display->getComponents() as $component_name => $component) {
if (!isset($field_definitions[$component_name])) {
continue;
}
/** @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */
$field_definition = $field_definitions[$component_name];
if ($component['type'] === 'entity_browser_entity_reference' && $field_definition->getFieldStorageDefinition()->getSetting('target_type') === 'media') {
$multiple = $field_definition->getFieldStorageDefinition()->getCardinality() !== 1;
$component['type'] = 'media_library_media_modify_widget';
$component['settings'] = [
'add_button_text' => Drupal::translation()->formatPlural($multiple ? 2 : 1, 'Select @label', 'Select @labels', [
'@label' => 'media item',
'@labels' => 'media items',
]),
'check_selected' => $multiple,
'form_mode' => 'override',
'no_edit_on_create' => $multiple,
'multi_edit_on_create' => FALSE,
'replace_checkbox_by_order_indicator' => $multiple,
];
$entity_form_display->setComponent($component_name, $component);
}
$entity_form_display->save();
}
}
/** @var \Drupal\ckeditor5\SmartDefaultSettings $ckEditorMigration */
$ckEditorMigration = new SmartDefaultSettings(
\Drupal::service('plugin.manager.ckeditor5.plugin'),
\Drupal::service('plugin.manager.public_ckeditor4to5upgrade.plugin'),
$updater->logger(),
\Drupal::service('module_handler'),
\Drupal::service('current_user'));
foreach (Editor::loadMultiple() as $editor) {
$format = $editor->getFilterFormat();
[$updated_text_editor] = $ckEditorMigration->computeSmartDefaultSettings($editor, $format);
$updated_text_editor->save();
}
/** @var \Drupal\Core\Extension\ModuleInstallerInterface $moduleInstaller */
$moduleInstaller = \Drupal::service('module_installer');
$moduleInstaller->uninstall([
'ckeditor',
'entity_browser',
'entity_browser_entity_form',
'dropzonejs_eb_widget',
]);
/** @var \Drupal\Core\Extension\ThemeInstallerInterface $themeInstaller */
$themeInstaller = \Drupal::service('theme_installer');
$themeInstaller->uninstall(['thunder_admin', 'seven']);
// Output logged messages to related channel of update execution.
return $updater->logger()->output();
}
/**
* Configure input formats to enable paragraphs split.
*/
function thunder_post_update_0002_enable_paragraphs_split(array &$sandbox): string {
/** @var \Drupal\update_helper\Updater $updater */
$updater = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updater->executeUpdate('thunder', 'thunder_post_update_0002_enable_paragraphs_split');
// Output logged messages to related channel of update execution.
return $updater->logger()->output();
}
/**
* Enable sticky action buttons for the Gin theme.
*/
function thunder_post_update_0003_enable_sticky_action_buttons(array &$sandbox): string {
\Drupal::configFactory()->getEditable('gin.settings')
->set('sticky_action_buttons', TRUE)
->save();
return t('Sticky action buttons enabled.');
}