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