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