system.post_update.php 2.42 KB
Newer Older
1 2 3 4 5 6 7
<?php

/**
 * @file
 * Post update functions for System.
 */

8 9 10 11
use Drupal\Core\Entity\Display\EntityDisplayInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;

12
/**
13
 * Re-save all configuration entities to recalculate dependencies.
14
 */
15 16 17 18 19
function system_post_update_recalculate_configuration_entity_dependencies(&$sandbox = NULL) {
  if (!isset($sandbox['config_names'])) {
    $sandbox['config_names'] = \Drupal::configFactory()->listAll();
    $sandbox['count'] = count($sandbox['config_names']);
  }
20 21
  /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
  $config_manager = \Drupal::service('config.manager');
22 23 24 25

  $count = 0;
  foreach ($sandbox['config_names'] as $key => $config_name) {
    if ($entity = $config_manager->loadConfigEntityByName($config_name)) {
26 27
      $entity->save();
    }
28 29 30 31 32 33
    unset($sandbox['config_names'][$key]);
    $count++;
    // Do 50 at a time.
    if ($count == 50) {
      break;
    }
34 35
  }

36 37
  $sandbox['#finished'] = empty($sandbox['config_names']) ? 1 : ($sandbox['count'] - count($sandbox['config_names'])) / $sandbox['count'];
  return t('Configuration dependencies recalculated');
38 39
}

40 41 42 43 44 45 46 47 48 49 50
/**
 * Update entity displays to contain the region for each field.
 */
function system_post_update_add_region_to_entity_displays() {
  $entity_save = function (EntityDisplayInterface $entity) {
    // preSave() will fill in the correct region based on the 'type'.
    $entity->save();
  };
  array_map($entity_save, EntityViewDisplay::loadMultiple());
  array_map($entity_save, EntityFormDisplay::loadMultiple());
}
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 58
  // Empty post-update hook.
}
59 60 61 62 63 64 65 66 67

/**
 * Force plugin definitions to be cleared.
 *
 * @see https://www.drupal.org/node/2802663
 */
function system_post_update_timestamp_plugins() {
  // Empty post-update hook.
}
68 69 70 71 72 73 74 75

/**
 * Clear caches to ensure Classy's message library is always added.
 */
function system_post_update_classy_message_library() {
  // Empty post-update hook.
}

76 77 78 79 80 81 82 83
/**
 * Force field type plugin definitions to be cleared.
 *
 * @see https://www.drupal.org/node/2403703
 */
function system_post_update_field_type_plugins() {
  // Empty post-update hook.
}
84 85 86 87 88 89 90

/**
 * Clear caches due to schema changes in core.entity.schema.yml.
 */
function system_post_update_field_formatter_entity_schema() {
  // Empty post-update hook.
}