comparison core/modules/system/system.post_update.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
3 /** 3 /**
4 * @file 4 * @file
5 * Post update functions for System. 5 * Post update functions for System.
6 */ 6 */
7 7
8 use Drupal\Core\Config\Entity\ConfigEntityUpdater;
8 use Drupal\Core\Entity\Display\EntityDisplayInterface; 9 use Drupal\Core\Entity\Display\EntityDisplayInterface;
10 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
9 use Drupal\Core\Entity\Entity\EntityFormDisplay; 11 use Drupal\Core\Entity\Entity\EntityFormDisplay;
10 use Drupal\Core\Entity\Entity\EntityViewDisplay; 12 use Drupal\Core\Entity\Entity\EntityViewDisplay;
11 13
12 /** 14 /**
13 * Re-save all configuration entities to recalculate dependencies. 15 * Re-save all configuration entities to recalculate dependencies.
46 $entity->save(); 48 $entity->save();
47 }; 49 };
48 array_map($entity_save, EntityViewDisplay::loadMultiple()); 50 array_map($entity_save, EntityViewDisplay::loadMultiple());
49 array_map($entity_save, EntityFormDisplay::loadMultiple()); 51 array_map($entity_save, EntityFormDisplay::loadMultiple());
50 } 52 }
51
52 53
53 /** 54 /**
54 * Force caches using hashes to be cleared (Twig, render cache, etc.). 55 * Force caches using hashes to be cleared (Twig, render cache, etc.).
55 */ 56 */
56 function system_post_update_hashes_clear_cache() { 57 function system_post_update_hashes_clear_cache() {
109 $action->setPlugin($old_new_action_id_map[$action->getPlugin()->getPluginId()]); 110 $action->setPlugin($old_new_action_id_map[$action->getPlugin()->getPluginId()]);
110 $action->save(); 111 $action->save();
111 } 112 }
112 } 113 }
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 }