system.post_update.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * @file
  4. * Post update functions for System.
  5. */
  6. use Drupal\Core\Entity\Display\EntityDisplayInterface;
  7. use Drupal\Core\Entity\Entity\EntityFormDisplay;
  8. use Drupal\Core\Entity\Entity\EntityViewDisplay;
  9. /**
  10. * Re-save all configuration entities to recalculate dependencies.
  11. */
  12. function system_post_update_recalculate_configuration_entity_dependencies(&$sandbox = NULL) {
  13. if (!isset($sandbox['config_names'])) {
  14. $sandbox['config_names'] = \Drupal::configFactory()->listAll();
  15. $sandbox['count'] = count($sandbox['config_names']);
  16. }
  17. /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
  18. $config_manager = \Drupal::service('config.manager');
  19. $count = 0;
  20. foreach ($sandbox['config_names'] as $key => $config_name) {
  21. if ($entity = $config_manager->loadConfigEntityByName($config_name)) {
  22. $entity->save();
  23. }
  24. unset($sandbox['config_names'][$key]);
  25. $count++;
  26. // Do 50 at a time.
  27. if ($count == 50) {
  28. break;
  29. }
  30. }
  31. $sandbox['#finished'] = empty($sandbox['config_names']) ? 1 : ($sandbox['count'] - count($sandbox['config_names'])) / $sandbox['count'];
  32. return t('Configuration dependencies recalculated');
  33. }
  34. /**
  35. * Update entity displays to contain the region for each field.
  36. */
  37. function system_post_update_add_region_to_entity_displays() {
  38. $entity_save = function (EntityDisplayInterface $entity) {
  39. // preSave() will fill in the correct region based on the 'type'.
  40. $entity->save();
  41. };
  42. array_map($entity_save, EntityViewDisplay::loadMultiple());
  43. array_map($entity_save, EntityFormDisplay::loadMultiple());
  44. }
  45. /**
  46. * Force caches using hashes to be cleared (Twig, render cache, etc.).
  47. */
  48. function system_post_update_hashes_clear_cache() {
  49. // Empty post-update hook.
  50. }
  51. /**
  52. * Force plugin definitions to be cleared.
  53. *
  54. * @see https://www.drupal.org/node/2802663
  55. */
  56. function system_post_update_timestamp_plugins() {
  57. // Empty post-update hook.
  58. }