Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Post update functions for System.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@17
|
8 use Drupal\Core\Config\Entity\ConfigEntityUpdater;
|
Chris@0
|
9 use Drupal\Core\Entity\Display\EntityDisplayInterface;
|
Chris@17
|
10 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
Chris@0
|
11 use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
Chris@0
|
12 use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Re-save all configuration entities to recalculate dependencies.
|
Chris@0
|
16 */
|
Chris@0
|
17 function system_post_update_recalculate_configuration_entity_dependencies(&$sandbox = NULL) {
|
Chris@0
|
18 if (!isset($sandbox['config_names'])) {
|
Chris@0
|
19 $sandbox['config_names'] = \Drupal::configFactory()->listAll();
|
Chris@0
|
20 $sandbox['count'] = count($sandbox['config_names']);
|
Chris@0
|
21 }
|
Chris@0
|
22 /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
|
Chris@0
|
23 $config_manager = \Drupal::service('config.manager');
|
Chris@0
|
24
|
Chris@0
|
25 $count = 0;
|
Chris@0
|
26 foreach ($sandbox['config_names'] as $key => $config_name) {
|
Chris@0
|
27 if ($entity = $config_manager->loadConfigEntityByName($config_name)) {
|
Chris@0
|
28 $entity->save();
|
Chris@0
|
29 }
|
Chris@0
|
30 unset($sandbox['config_names'][$key]);
|
Chris@0
|
31 $count++;
|
Chris@0
|
32 // Do 50 at a time.
|
Chris@0
|
33 if ($count == 50) {
|
Chris@0
|
34 break;
|
Chris@0
|
35 }
|
Chris@0
|
36 }
|
Chris@0
|
37
|
Chris@0
|
38 $sandbox['#finished'] = empty($sandbox['config_names']) ? 1 : ($sandbox['count'] - count($sandbox['config_names'])) / $sandbox['count'];
|
Chris@0
|
39 return t('Configuration dependencies recalculated');
|
Chris@0
|
40 }
|
Chris@0
|
41
|
Chris@0
|
42 /**
|
Chris@0
|
43 * Update entity displays to contain the region for each field.
|
Chris@0
|
44 */
|
Chris@0
|
45 function system_post_update_add_region_to_entity_displays() {
|
Chris@0
|
46 $entity_save = function (EntityDisplayInterface $entity) {
|
Chris@0
|
47 // preSave() will fill in the correct region based on the 'type'.
|
Chris@0
|
48 $entity->save();
|
Chris@0
|
49 };
|
Chris@0
|
50 array_map($entity_save, EntityViewDisplay::loadMultiple());
|
Chris@0
|
51 array_map($entity_save, EntityFormDisplay::loadMultiple());
|
Chris@0
|
52 }
|
Chris@0
|
53
|
Chris@0
|
54 /**
|
Chris@0
|
55 * Force caches using hashes to be cleared (Twig, render cache, etc.).
|
Chris@0
|
56 */
|
Chris@0
|
57 function system_post_update_hashes_clear_cache() {
|
Chris@0
|
58 // Empty post-update hook.
|
Chris@0
|
59 }
|
Chris@0
|
60
|
Chris@0
|
61 /**
|
Chris@0
|
62 * Force plugin definitions to be cleared.
|
Chris@0
|
63 *
|
Chris@0
|
64 * @see https://www.drupal.org/node/2802663
|
Chris@0
|
65 */
|
Chris@0
|
66 function system_post_update_timestamp_plugins() {
|
Chris@0
|
67 // Empty post-update hook.
|
Chris@0
|
68 }
|
Chris@0
|
69
|
Chris@0
|
70 /**
|
Chris@0
|
71 * Clear caches to ensure Classy's message library is always added.
|
Chris@0
|
72 */
|
Chris@0
|
73 function system_post_update_classy_message_library() {
|
Chris@0
|
74 // Empty post-update hook.
|
Chris@0
|
75 }
|
Chris@0
|
76
|
Chris@0
|
77 /**
|
Chris@0
|
78 * Force field type plugin definitions to be cleared.
|
Chris@0
|
79 *
|
Chris@0
|
80 * @see https://www.drupal.org/node/2403703
|
Chris@0
|
81 */
|
Chris@0
|
82 function system_post_update_field_type_plugins() {
|
Chris@0
|
83 // Empty post-update hook.
|
Chris@0
|
84 }
|
Chris@14
|
85
|
Chris@14
|
86 /**
|
Chris@14
|
87 * Clear caches due to schema changes in core.entity.schema.yml.
|
Chris@14
|
88 */
|
Chris@14
|
89 function system_post_update_field_formatter_entity_schema() {
|
Chris@14
|
90 // Empty post-update hook.
|
Chris@14
|
91 }
|
Chris@14
|
92
|
Chris@14
|
93 /**
|
Chris@18
|
94 * Clear the library cache and ensure aggregate files are regenerated.
|
Chris@18
|
95 */
|
Chris@18
|
96 function system_post_update_fix_jquery_extend() {
|
Chris@18
|
97 // Empty post-update hook.
|
Chris@18
|
98 }
|
Chris@18
|
99
|
Chris@18
|
100 /**
|
Chris@14
|
101 * Change plugin IDs of actions.
|
Chris@14
|
102 */
|
Chris@14
|
103 function system_post_update_change_action_plugins() {
|
Chris@14
|
104 $old_new_action_id_map = [
|
Chris@14
|
105 'comment_publish_action' => 'entity:publish_action:comment',
|
Chris@14
|
106 'comment_unpublish_action' => 'entity:unpublish_action:comment',
|
Chris@14
|
107 'comment_save_action' => 'entity:save_action:comment',
|
Chris@14
|
108 'node_publish_action' => 'entity:publish_action:node',
|
Chris@14
|
109 'node_unpublish_action' => 'entity:unpublish_action:node',
|
Chris@14
|
110 'node_save_action' => 'entity:save_action:node',
|
Chris@14
|
111 ];
|
Chris@14
|
112
|
Chris@14
|
113 /** @var \Drupal\system\Entity\Action[] $actions */
|
Chris@14
|
114 $actions = \Drupal::entityTypeManager()->getStorage('action')->loadMultiple();
|
Chris@14
|
115 foreach ($actions as $action) {
|
Chris@14
|
116 if (isset($old_new_action_id_map[$action->getPlugin()->getPluginId()])) {
|
Chris@14
|
117 $action->setPlugin($old_new_action_id_map[$action->getPlugin()->getPluginId()]);
|
Chris@14
|
118 $action->save();
|
Chris@14
|
119 }
|
Chris@14
|
120 }
|
Chris@14
|
121 }
|
Chris@17
|
122
|
Chris@17
|
123 /**
|
Chris@17
|
124 * Change plugin IDs of delete actions.
|
Chris@17
|
125 */
|
Chris@17
|
126 function system_post_update_change_delete_action_plugins() {
|
Chris@17
|
127 $old_new_action_id_map = [
|
Chris@17
|
128 'comment_delete_action' => 'entity:delete_action:comment',
|
Chris@17
|
129 'node_delete_action' => 'entity:delete_action:node',
|
Chris@17
|
130 ];
|
Chris@17
|
131
|
Chris@17
|
132 /** @var \Drupal\system\Entity\Action[] $actions */
|
Chris@17
|
133 $actions = \Drupal::entityTypeManager()->getStorage('action')->loadMultiple();
|
Chris@17
|
134 foreach ($actions as $action) {
|
Chris@17
|
135 if (isset($old_new_action_id_map[$action->getPlugin()->getPluginId()])) {
|
Chris@17
|
136 $action->setPlugin($old_new_action_id_map[$action->getPlugin()->getPluginId()]);
|
Chris@17
|
137 $action->save();
|
Chris@17
|
138 }
|
Chris@17
|
139 }
|
Chris@17
|
140 }
|
Chris@17
|
141
|
Chris@17
|
142 /**
|
Chris@17
|
143 * Force cache clear for language item callback.
|
Chris@17
|
144 *
|
Chris@17
|
145 * @see https://www.drupal.org/node/2851736
|
Chris@17
|
146 */
|
Chris@17
|
147 function system_post_update_language_item_callback() {
|
Chris@17
|
148 // Empty post-update hook.
|
Chris@17
|
149 }
|
Chris@17
|
150
|
Chris@17
|
151 /**
|
Chris@17
|
152 * Update all entity displays that contain extra fields.
|
Chris@17
|
153 */
|
Chris@17
|
154 function system_post_update_extra_fields(&$sandbox = NULL) {
|
Chris@17
|
155 $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);
|
Chris@17
|
156 $entity_field_manager = \Drupal::service('entity_field.manager');
|
Chris@17
|
157
|
Chris@17
|
158 $callback = function (EntityDisplayInterface $display) use ($entity_field_manager) {
|
Chris@17
|
159 $display_context = $display instanceof EntityViewDisplayInterface ? 'display' : 'form';
|
Chris@17
|
160 $extra_fields = $entity_field_manager->getExtraFields($display->getTargetEntityTypeId(), $display->getTargetBundle());
|
Chris@17
|
161
|
Chris@17
|
162 // If any extra fields are used as a component, resave the display with the
|
Chris@17
|
163 // updated component information.
|
Chris@17
|
164 $needs_save = FALSE;
|
Chris@17
|
165 if (!empty($extra_fields[$display_context])) {
|
Chris@17
|
166 foreach ($extra_fields[$display_context] as $name => $extra_field) {
|
Chris@17
|
167 if ($component = $display->getComponent($name)) {
|
Chris@17
|
168 $display->setComponent($name, $component);
|
Chris@17
|
169 $needs_save = TRUE;
|
Chris@17
|
170 }
|
Chris@17
|
171 }
|
Chris@17
|
172 }
|
Chris@17
|
173 return $needs_save;
|
Chris@17
|
174 };
|
Chris@17
|
175
|
Chris@17
|
176 $config_entity_updater->update($sandbox, 'entity_form_display', $callback);
|
Chris@17
|
177 $config_entity_updater->update($sandbox, 'entity_view_display', $callback);
|
Chris@17
|
178 }
|
Chris@17
|
179
|
Chris@17
|
180 /**
|
Chris@17
|
181 * Force cache clear to ensure aggregated JavaScript files are regenerated.
|
Chris@17
|
182 *
|
Chris@17
|
183 * @see https://www.drupal.org/project/drupal/issues/2995570
|
Chris@17
|
184 */
|
Chris@17
|
185 function system_post_update_states_clear_cache() {
|
Chris@17
|
186 // Empty post-update hook.
|
Chris@17
|
187 }
|
Chris@18
|
188
|
Chris@18
|
189 /**
|
Chris@18
|
190 * Initialize 'expand_all_items' values to system_menu_block.
|
Chris@18
|
191 */
|
Chris@18
|
192 function system_post_update_add_expand_all_items_key_in_system_menu_block(&$sandbox = NULL) {
|
Chris@18
|
193 if (!\Drupal::moduleHandler()->moduleExists('block')) {
|
Chris@18
|
194 return;
|
Chris@18
|
195 }
|
Chris@18
|
196 \Drupal::classResolver(ConfigEntityUpdater::class)->update($sandbox, 'block', function ($block) {
|
Chris@18
|
197 return strpos($block->getPluginId(), 'system_menu_block:') === 0;
|
Chris@18
|
198 });
|
Chris@18
|
199 }
|
Chris@18
|
200
|
Chris@18
|
201 /**
|
Chris@18
|
202 * Clear the menu cache.
|
Chris@18
|
203 *
|
Chris@18
|
204 * @see https://www.drupal.org/project/drupal/issues/3044364
|
Chris@18
|
205 */
|
Chris@18
|
206 function system_post_update_clear_menu_cache() {
|
Chris@18
|
207 // Empty post-update hook.
|
Chris@18
|
208 }
|