You are here

config_entity_static_cache_test.module in Drupal 9

Provides configuration entity static cache test helpers.

File

core/modules/config/tests/config_entity_static_cache_test/config_entity_static_cache_test.module
View source
<?php

/**
 * @file
 * Provides configuration entity static cache test helpers.
 */
use Drupal\Component\Utility\Random;

/**
 * Implements hook_ENTITY_TYPE_load() for 'static_cache_test_config_test'.
 */
function config_entity_static_cache_test_config_test_load($entities) {
  static $random;
  if (!$random) {
    $random = new Random();
  }
  foreach ($entities as $entity) {

    // Add a random stamp for every load(), so that during tests, we can tell
    // if an entity was retrieved from cache (unchanged stamp) or reloaded.
    $entity->_loadStamp = $random
      ->string(8, TRUE);
  }
}

/**
 * Implements hook_entity_type_alter().
 */
function config_entity_static_cache_test_entity_type_alter(array &$entity_types) {

  /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
  $entity_types['config_test']
    ->set('static_cache', TRUE);
}