CacheTestController.php in Drupal 10
File
core/modules/system/tests/modules/cache_test/src/Controller/CacheTestController.php
View source
<?php
namespace Drupal\cache_test\Controller;
use Drupal\Core\Url;
class CacheTestController {
public function urlBubbling() {
$url = Url::fromRoute('<current>')
->setAbsolute();
return [
'#markup' => 'This URL is early-rendered: ' . $url
->toString() . '. Yet, its bubbleable metadata should be bubbled.',
];
}
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;
}
}