annotate 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
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@0 8 use Drupal\Core\Entity\Display\EntityDisplayInterface;
Chris@0 9 use Drupal\Core\Entity\Entity\EntityFormDisplay;
Chris@0 10 use Drupal\Core\Entity\Entity\EntityViewDisplay;
Chris@0 11
Chris@0 12 /**
Chris@0 13 * Re-save all configuration entities to recalculate dependencies.
Chris@0 14 */
Chris@0 15 function system_post_update_recalculate_configuration_entity_dependencies(&$sandbox = NULL) {
Chris@0 16 if (!isset($sandbox['config_names'])) {
Chris@0 17 $sandbox['config_names'] = \Drupal::configFactory()->listAll();
Chris@0 18 $sandbox['count'] = count($sandbox['config_names']);
Chris@0 19 }
Chris@0 20 /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
Chris@0 21 $config_manager = \Drupal::service('config.manager');
Chris@0 22
Chris@0 23 $count = 0;
Chris@0 24 foreach ($sandbox['config_names'] as $key => $config_name) {
Chris@0 25 if ($entity = $config_manager->loadConfigEntityByName($config_name)) {
Chris@0 26 $entity->save();
Chris@0 27 }
Chris@0 28 unset($sandbox['config_names'][$key]);
Chris@0 29 $count++;
Chris@0 30 // Do 50 at a time.
Chris@0 31 if ($count == 50) {
Chris@0 32 break;
Chris@0 33 }
Chris@0 34 }
Chris@0 35
Chris@0 36 $sandbox['#finished'] = empty($sandbox['config_names']) ? 1 : ($sandbox['count'] - count($sandbox['config_names'])) / $sandbox['count'];
Chris@0 37 return t('Configuration dependencies recalculated');
Chris@0 38 }
Chris@0 39
Chris@0 40 /**
Chris@0 41 * Update entity displays to contain the region for each field.
Chris@0 42 */
Chris@0 43 function system_post_update_add_region_to_entity_displays() {
Chris@0 44 $entity_save = function (EntityDisplayInterface $entity) {
Chris@0 45 // preSave() will fill in the correct region based on the 'type'.
Chris@0 46 $entity->save();
Chris@0 47 };
Chris@0 48 array_map($entity_save, EntityViewDisplay::loadMultiple());
Chris@0 49 array_map($entity_save, EntityFormDisplay::loadMultiple());
Chris@0 50 }
Chris@0 51
Chris@0 52
Chris@0 53 /**
Chris@0 54 * Force caches using hashes to be cleared (Twig, render cache, etc.).
Chris@0 55 */
Chris@0 56 function system_post_update_hashes_clear_cache() {
Chris@0 57 // Empty post-update hook.
Chris@0 58 }
Chris@0 59
Chris@0 60 /**
Chris@0 61 * Force plugin definitions to be cleared.
Chris@0 62 *
Chris@0 63 * @see https://www.drupal.org/node/2802663
Chris@0 64 */
Chris@0 65 function system_post_update_timestamp_plugins() {
Chris@0 66 // Empty post-update hook.
Chris@0 67 }
Chris@0 68
Chris@0 69 /**
Chris@0 70 * Clear caches to ensure Classy's message library is always added.
Chris@0 71 */
Chris@0 72 function system_post_update_classy_message_library() {
Chris@0 73 // Empty post-update hook.
Chris@0 74 }
Chris@0 75
Chris@0 76 /**
Chris@0 77 * Force field type plugin definitions to be cleared.
Chris@0 78 *
Chris@0 79 * @see https://www.drupal.org/node/2403703
Chris@0 80 */
Chris@0 81 function system_post_update_field_type_plugins() {
Chris@0 82 // Empty post-update hook.
Chris@0 83 }