annotate core/modules/system/system.post_update.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children 12f9dff5fda9
rev   line source
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@4 8 use Drupal\Core\Config\Entity\ConfigEntityUpdater;
Chris@0 9 use Drupal\Core\Entity\Display\EntityDisplayInterface;
Chris@4 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@0 85
Chris@0 86 /**
Chris@0 87 * Clear caches due to schema changes in core.entity.schema.yml.
Chris@0 88 */
Chris@0 89 function system_post_update_field_formatter_entity_schema() {
Chris@0 90 // Empty post-update hook.
Chris@0 91 }
Chris@0 92
Chris@0 93 /**
Chris@0 94 * Change plugin IDs of actions.
Chris@0 95 */
Chris@0 96 function system_post_update_change_action_plugins() {
Chris@0 97 $old_new_action_id_map = [
Chris@0 98 'comment_publish_action' => 'entity:publish_action:comment',
Chris@0 99 'comment_unpublish_action' => 'entity:unpublish_action:comment',
Chris@0 100 'comment_save_action' => 'entity:save_action:comment',
Chris@0 101 'node_publish_action' => 'entity:publish_action:node',
Chris@0 102 'node_unpublish_action' => 'entity:unpublish_action:node',
Chris@0 103 'node_save_action' => 'entity:save_action:node',
Chris@0 104 ];
Chris@0 105
Chris@0 106 /** @var \Drupal\system\Entity\Action[] $actions */
Chris@0 107 $actions = \Drupal::entityTypeManager()->getStorage('action')->loadMultiple();
Chris@0 108 foreach ($actions as $action) {
Chris@0 109 if (isset($old_new_action_id_map[$action->getPlugin()->getPluginId()])) {
Chris@0 110 $action->setPlugin($old_new_action_id_map[$action->getPlugin()->getPluginId()]);
Chris@0 111 $action->save();
Chris@0 112 }
Chris@0 113 }
Chris@0 114 }
Chris@4 115
Chris@4 116 /**
Chris@4 117 * Change plugin IDs of delete actions.
Chris@4 118 */
Chris@4 119 function system_post_update_change_delete_action_plugins() {
Chris@4 120 $old_new_action_id_map = [
Chris@4 121 'comment_delete_action' => 'entity:delete_action:comment',
Chris@4 122 'node_delete_action' => 'entity:delete_action:node',
Chris@4 123 ];
Chris@4 124
Chris@4 125 /** @var \Drupal\system\Entity\Action[] $actions */
Chris@4 126 $actions = \Drupal::entityTypeManager()->getStorage('action')->loadMultiple();
Chris@4 127 foreach ($actions as $action) {
Chris@4 128 if (isset($old_new_action_id_map[$action->getPlugin()->getPluginId()])) {
Chris@4 129 $action->setPlugin($old_new_action_id_map[$action->getPlugin()->getPluginId()]);
Chris@4 130 $action->save();
Chris@4 131 }
Chris@4 132 }
Chris@4 133 }
Chris@4 134
Chris@4 135 /**
Chris@4 136 * Force cache clear for language item callback.
Chris@4 137 *
Chris@4 138 * @see https://www.drupal.org/node/2851736
Chris@4 139 */
Chris@4 140 function system_post_update_language_item_callback() {
Chris@4 141 // Empty post-update hook.
Chris@4 142 }
Chris@4 143
Chris@4 144 /**
Chris@4 145 * Update all entity displays that contain extra fields.
Chris@4 146 */
Chris@4 147 function system_post_update_extra_fields(&$sandbox = NULL) {
Chris@4 148 $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);
Chris@4 149 $entity_field_manager = \Drupal::service('entity_field.manager');
Chris@4 150
Chris@4 151 $callback = function (EntityDisplayInterface $display) use ($entity_field_manager) {
Chris@4 152 $display_context = $display instanceof EntityViewDisplayInterface ? 'display' : 'form';
Chris@4 153 $extra_fields = $entity_field_manager->getExtraFields($display->getTargetEntityTypeId(), $display->getTargetBundle());
Chris@4 154
Chris@4 155 // If any extra fields are used as a component, resave the display with the
Chris@4 156 // updated component information.
Chris@4 157 $needs_save = FALSE;
Chris@4 158 if (!empty($extra_fields[$display_context])) {
Chris@4 159 foreach ($extra_fields[$display_context] as $name => $extra_field) {
Chris@4 160 if ($component = $display->getComponent($name)) {
Chris@4 161 $display->setComponent($name, $component);
Chris@4 162 $needs_save = TRUE;
Chris@4 163 }
Chris@4 164 }
Chris@4 165 }
Chris@4 166 return $needs_save;
Chris@4 167 };
Chris@4 168
Chris@4 169 $config_entity_updater->update($sandbox, 'entity_form_display', $callback);
Chris@4 170 $config_entity_updater->update($sandbox, 'entity_view_display', $callback);
Chris@4 171 }
Chris@4 172
Chris@4 173 /**
Chris@4 174 * Force cache clear to ensure aggregated JavaScript files are regenerated.
Chris@4 175 *
Chris@4 176 * @see https://www.drupal.org/project/drupal/issues/2995570
Chris@4 177 */
Chris@4 178 function system_post_update_states_clear_cache() {
Chris@4 179 // Empty post-update hook.
Chris@4 180 }