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@0
|
8 use Drupal\Core\Entity\Display\EntityDisplayInterface;
|
Chris@0
|
9 use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
Chris@0
|
10 use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
Chris@0
|
11
|
Chris@0
|
12 /**
|
Chris@0
|
13 * Re-save all configuration entities to recalculate dependencies.
|
Chris@0
|
14 */
|
Chris@0
|
15 function system_post_update_recalculate_configuration_entity_dependencies(&$sandbox = NULL) {
|
Chris@0
|
16 if (!isset($sandbox['config_names'])) {
|
Chris@0
|
17 $sandbox['config_names'] = \Drupal::configFactory()->listAll();
|
Chris@0
|
18 $sandbox['count'] = count($sandbox['config_names']);
|
Chris@0
|
19 }
|
Chris@0
|
20 /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
|
Chris@0
|
21 $config_manager = \Drupal::service('config.manager');
|
Chris@0
|
22
|
Chris@0
|
23 $count = 0;
|
Chris@0
|
24 foreach ($sandbox['config_names'] as $key => $config_name) {
|
Chris@0
|
25 if ($entity = $config_manager->loadConfigEntityByName($config_name)) {
|
Chris@0
|
26 $entity->save();
|
Chris@0
|
27 }
|
Chris@0
|
28 unset($sandbox['config_names'][$key]);
|
Chris@0
|
29 $count++;
|
Chris@0
|
30 // Do 50 at a time.
|
Chris@0
|
31 if ($count == 50) {
|
Chris@0
|
32 break;
|
Chris@0
|
33 }
|
Chris@0
|
34 }
|
Chris@0
|
35
|
Chris@0
|
36 $sandbox['#finished'] = empty($sandbox['config_names']) ? 1 : ($sandbox['count'] - count($sandbox['config_names'])) / $sandbox['count'];
|
Chris@0
|
37 return t('Configuration dependencies recalculated');
|
Chris@0
|
38 }
|
Chris@0
|
39
|
Chris@0
|
40 /**
|
Chris@0
|
41 * Update entity displays to contain the region for each field.
|
Chris@0
|
42 */
|
Chris@0
|
43 function system_post_update_add_region_to_entity_displays() {
|
Chris@0
|
44 $entity_save = function (EntityDisplayInterface $entity) {
|
Chris@0
|
45 // preSave() will fill in the correct region based on the 'type'.
|
Chris@0
|
46 $entity->save();
|
Chris@0
|
47 };
|
Chris@0
|
48 array_map($entity_save, EntityViewDisplay::loadMultiple());
|
Chris@0
|
49 array_map($entity_save, EntityFormDisplay::loadMultiple());
|
Chris@0
|
50 }
|
Chris@0
|
51
|
Chris@0
|
52
|
Chris@0
|
53 /**
|
Chris@0
|
54 * Force caches using hashes to be cleared (Twig, render cache, etc.).
|
Chris@0
|
55 */
|
Chris@0
|
56 function system_post_update_hashes_clear_cache() {
|
Chris@0
|
57 // Empty post-update hook.
|
Chris@0
|
58 }
|
Chris@0
|
59
|
Chris@0
|
60 /**
|
Chris@0
|
61 * Force plugin definitions to be cleared.
|
Chris@0
|
62 *
|
Chris@0
|
63 * @see https://www.drupal.org/node/2802663
|
Chris@0
|
64 */
|
Chris@0
|
65 function system_post_update_timestamp_plugins() {
|
Chris@0
|
66 // Empty post-update hook.
|
Chris@0
|
67 }
|
Chris@0
|
68
|
Chris@0
|
69 /**
|
Chris@0
|
70 * Clear caches to ensure Classy's message library is always added.
|
Chris@0
|
71 */
|
Chris@0
|
72 function system_post_update_classy_message_library() {
|
Chris@0
|
73 // Empty post-update hook.
|
Chris@0
|
74 }
|
Chris@0
|
75
|
Chris@0
|
76 /**
|
Chris@0
|
77 * Force field type plugin definitions to be cleared.
|
Chris@0
|
78 *
|
Chris@0
|
79 * @see https://www.drupal.org/node/2403703
|
Chris@0
|
80 */
|
Chris@0
|
81 function system_post_update_field_type_plugins() {
|
Chris@0
|
82 // Empty post-update hook.
|
Chris@0
|
83 }
|
Chris@0
|
84
|
Chris@0
|
85 /**
|
Chris@0
|
86 * Clear caches due to schema changes in core.entity.schema.yml.
|
Chris@0
|
87 */
|
Chris@0
|
88 function system_post_update_field_formatter_entity_schema() {
|
Chris@0
|
89 // Empty post-update hook.
|
Chris@0
|
90 }
|
Chris@0
|
91
|
Chris@0
|
92 /**
|
Chris@0
|
93 * Change plugin IDs of actions.
|
Chris@0
|
94 */
|
Chris@0
|
95 function system_post_update_change_action_plugins() {
|
Chris@0
|
96 $old_new_action_id_map = [
|
Chris@0
|
97 'comment_publish_action' => 'entity:publish_action:comment',
|
Chris@0
|
98 'comment_unpublish_action' => 'entity:unpublish_action:comment',
|
Chris@0
|
99 'comment_save_action' => 'entity:save_action:comment',
|
Chris@0
|
100 'node_publish_action' => 'entity:publish_action:node',
|
Chris@0
|
101 'node_unpublish_action' => 'entity:unpublish_action:node',
|
Chris@0
|
102 'node_save_action' => 'entity:save_action:node',
|
Chris@0
|
103 ];
|
Chris@0
|
104
|
Chris@0
|
105 /** @var \Drupal\system\Entity\Action[] $actions */
|
Chris@0
|
106 $actions = \Drupal::entityTypeManager()->getStorage('action')->loadMultiple();
|
Chris@0
|
107 foreach ($actions as $action) {
|
Chris@0
|
108 if (isset($old_new_action_id_map[$action->getPlugin()->getPluginId()])) {
|
Chris@0
|
109 $action->setPlugin($old_new_action_id_map[$action->getPlugin()->getPluginId()]);
|
Chris@0
|
110 $action->save();
|
Chris@0
|
111 }
|
Chris@0
|
112 }
|
Chris@0
|
113 }
|