From 8a52fd3be68f12cab4b0e110407e313f011627a1 Mon Sep 17 00:00:00 2001 From: Paul Weidner Date: Thu, 10 Aug 2023 17:55:11 -0700 Subject: [PATCH] Add cache metadata to quick form controller --- .../core/quick/src/Controller/QuickFormController.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/core/quick/src/Controller/QuickFormController.php b/modules/core/quick/src/Controller/QuickFormController.php index 0baa0b9be..b75661fa6 100644 --- a/modules/core/quick/src/Controller/QuickFormController.php +++ b/modules/core/quick/src/Controller/QuickFormController.php @@ -2,6 +2,7 @@ namespace Drupal\farm_quick\Controller; +use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; @@ -48,12 +49,19 @@ class QuickFormController extends ControllerBase { * Returns a render array. */ public function index(): array { + + // Start cacheability object with quick form config entity list tag. + $cacheability = new CacheableMetadata(); + $cacheability->addCacheTags($this->entityTypeManager()->getStorage('quick_form')->getEntityType()->getListCacheTags()); + + // Build list item for each quick form. /** @var \Drupal\farm_quick\Entity\QuickFormInstanceInterface[] $quick_forms */ $quick_forms = $this->quickFormInstanceManager->getInstances(); $items = []; foreach ($quick_forms as $id => $quick_form) { $url = Url::fromRoute('farm_quick.quick_form', ['quick_form' => $id]); if ($url->access()) { + $cacheability->addCacheableDependency($quick_form); $items[] = [ 'title' => $quick_form->getLabel(), 'description' => $quick_form->getDescription(), @@ -72,6 +80,7 @@ class QuickFormController extends ControllerBase { '#markup' => $this->t('You do not have any quick forms.'), ]; } + $cacheability->applyTo($output); return $output; }