5 * Post update functions for System.
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;
15 * Re-save all configuration entities to recalculate dependencies.
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']);
22 /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
23 $config_manager = \Drupal::service('config.manager');
26 foreach ($sandbox['config_names'] as $key => $config_name) {
27 if ($entity = $config_manager->loadConfigEntityByName($config_name)) {
30 unset($sandbox['config_names'][$key]);
38 $sandbox['#finished'] = empty($sandbox['config_names']) ? 1 : ($sandbox['count'] - count($sandbox['config_names'])) / $sandbox['count'];
39 return t('Configuration dependencies recalculated');
43 * Update entity displays to contain the region for each field.
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'.
50 array_map($entity_save, EntityViewDisplay::loadMultiple());
51 array_map($entity_save, EntityFormDisplay::loadMultiple());
55 * Force caches using hashes to be cleared (Twig, render cache, etc.).
57 function system_post_update_hashes_clear_cache() {
58 // Empty post-update hook.
62 * Force plugin definitions to be cleared.
64 * @see https://www.drupal.org/node/2802663
66 function system_post_update_timestamp_plugins() {
67 // Empty post-update hook.
71 * Clear caches to ensure Classy's message library is always added.
73 function system_post_update_classy_message_library() {
74 // Empty post-update hook.
78 * Force field type plugin definitions to be cleared.
80 * @see https://www.drupal.org/node/2403703
82 function system_post_update_field_type_plugins() {
83 // Empty post-update hook.
87 * Clear caches due to schema changes in core.entity.schema.yml.
89 function system_post_update_field_formatter_entity_schema() {
90 // Empty post-update hook.
94 * Change plugin IDs of actions.
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',
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()]);
117 * Change plugin IDs of delete actions.
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',
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()]);
136 * Force cache clear for language item callback.
138 * @see https://www.drupal.org/node/2851736
140 function system_post_update_language_item_callback() {
141 // Empty post-update hook.
145 * Update all entity displays that contain extra fields.
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');
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());
155 // If any extra fields are used as a component, resave the display with the
156 // updated component information.
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);
169 $config_entity_updater->update($sandbox, 'entity_form_display', $callback);
170 $config_entity_updater->update($sandbox, 'entity_view_display', $callback);
174 * Force cache clear to ensure aggregated JavaScript files are regenerated.
176 * @see https://www.drupal.org/project/drupal/issues/2995570
178 function system_post_update_states_clear_cache() {
179 // Empty post-update hook.