Skip to content

Commit

Permalink
Merge pull request #1051 from plentymarkets/hotfix/catch_context_errors
Browse files Browse the repository at this point in the history
disable content cache if context initialization failed
  • Loading branch information
felixdausch authored Nov 15, 2021
2 parents 32d53e3 + 49eff5e commit 5d44fa4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Extensions/TwigTemplateContextExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 [];
Expand Down

0 comments on commit 5d44fa4

Please sign in to comment.