From dee6051cd907068f801dd67a089949213b39e059 Mon Sep 17 00:00:00 2001 From: Oliver Davies <oliver@oliverdavies.uk> Date: Mon, 11 Jan 2021 02:32:17 +0000 Subject: [PATCH] Add route cache context to related posts block References #3 --- .../custom/blog/src/Plugin/Block/RelatedPostsBlock.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web/modules/custom/blog/src/Plugin/Block/RelatedPostsBlock.php b/web/modules/custom/blog/src/Plugin/Block/RelatedPostsBlock.php index c7f9141..69ccdb1 100644 --- a/web/modules/custom/blog/src/Plugin/Block/RelatedPostsBlock.php +++ b/web/modules/custom/blog/src/Plugin/Block/RelatedPostsBlock.php @@ -80,6 +80,10 @@ class RelatedPostsBlock extends BlockBase implements ContainerFactoryPluginInter return 604800; } + public function getCacheContexts(): array { + return Cache::mergeContexts(parent::getCacheContexts(), ['route']); + } + public function getCacheTags(): array { /** @var Post $post */ $post = $this->currentRouteMatch->getParameter('node');