class CacheTestController

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/cache_test/src/Controller/CacheTestController.php \Drupal\cache_test\Controller\CacheTestController
  2. 8.9.x core/modules/system/tests/modules/cache_test/src/Controller/CacheTestController.php \Drupal\cache_test\Controller\CacheTestController
  3. 11.x core/modules/system/tests/modules/cache_test/src/Controller/CacheTestController.php \Drupal\cache_test\Controller\CacheTestController

Controller routines for cache_test routes.

Hierarchy

Expanded class hierarchy of CacheTestController

File

core/modules/system/tests/modules/cache_test/src/Controller/CacheTestController.php, line 10

Namespace

Drupal\cache_test\Controller
View source
class CacheTestController {
  
  /**
   * Early renders a URL to test bubbleable metadata bubbling.
   */
  public function urlBubbling() {
    $url = Url::fromRoute('<current>')->setAbsolute();
    return [
      '#markup' => 'This URL is early-rendered: ' . $url->toString() . '. Yet, its bubbleable metadata should be bubbled.',
    ];
  }
  
  /**
   * Bundle listing tags invalidation.
   *
   * @param string $entity_type_id
   *   The entity type ID.
   * @param string $bundle
   *   The bundle.
   *
   * @return array
   *   Renderable array.
   */
  public function bundleTags($entity_type_id, $bundle) {
    $storage = \Drupal::entityTypeManager()->getStorage($entity_type_id);
    $entity_ids = $storage->getQuery()
      ->accessCheck(TRUE)
      ->condition('type', $bundle)
      ->execute();
    $page = [];
    $entities = $storage->loadMultiple($entity_ids);
    foreach ($entities as $entity) {
      $page[$entity->id()] = [
        '#markup' => $entity->label(),
      ];
    }
    $page['#cache']['tags'] = [
      $entity_type_id . '_list:' . $bundle,
    ];
    return $page;
  }

}

Members

Title Sort descending Modifiers Object type Summary
CacheTestController::bundleTags public function Bundle listing tags invalidation.
CacheTestController::urlBubbling public function Early renders a URL to test bubbleable metadata bubbling.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.