comparison core/modules/system/system.post_update.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
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 }