From 49eff5efbd19299c2292b0c06d8200ca31a7a6e3 Mon Sep 17 00:00:00 2001 From: Felix Dausch Date: Mon, 15 Nov 2021 11:46:09 +0100 Subject: [PATCH] disable content cache if context initialization failed --- src/Extensions/TwigTemplateContextExtension.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Extensions/TwigTemplateContextExtension.php b/src/Extensions/TwigTemplateContextExtension.php index ce517356e..b81ab068f 100644 --- a/src/Extensions/TwigTemplateContextExtension.php +++ b/src/Extensions/TwigTemplateContextExtension.php @@ -7,6 +7,7 @@ use IO\Helper\EventDispatcher; use IO\Helper\TemplateContainer; use IO\Services\TemplateService; +use Plenty\Modules\ContentCache\Contracts\ContentCacheRepositoryContract; use Plenty\Plugin\Templates\Extensions\Twig_Extension; class TwigTemplateContextExtension extends Twig_Extension @@ -64,7 +65,14 @@ public function getGlobals(): array $context->init(TemplateService::$currentTemplateData); } - return ArrayHelper::toArray($context); + $contextArray = ArrayHelper::toArray($context); + if(is_null($contextArray)) { + /** @var ContentCacheRepositoryContract $contentCacheRepository */ + $contentCacheRepository = pluginApp(ContentCacheRepositoryContract::class); + $contentCacheRepository->disableCacheForResponse('Twig context could not be initialized'); + return []; + } + return $contextArray; } return [];