Skip to content

Commit

Permalink
[BUGFIX] remove deprecated cache from constant viewhelper
Browse files Browse the repository at this point in the history
Signed-off-by: Kay Strobach <[email protected]>
  • Loading branch information
kaystrobach committed Oct 8, 2022
1 parent 795bc73 commit 9e7761e
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions Classes/ViewHelpers/ConstantViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function initializeArguments()
{
$this->registerArgument('constant', 'string', 'the constant path', false, '');
}

/**
* Gets a constant
*
Expand All @@ -45,43 +45,15 @@ public function initializeArguments()
public function render()
{
$constant = $this->arguments['constant'];

$pageWithTheme = \KayStrobach\Themes\Utilities\FindParentPageWithThemeUtility::find($this->getFrontendController()->id);
$pageLanguage = (int)GeneralUtility::_GP('L');
// instantiate the cache
/** @var \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache */
$cache = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('themes_cache');
$cacheLifeTime = 60 * 60 * 24 * 7 * 365 * 20;
$cacheIdentifierString = 'theme-of-page-' . $pageWithTheme . '-of-language-' . $pageLanguage;
$cacheIdentifier = sha1($cacheIdentifierString);

// If flatSetup is available, cache it
$flatSetup = $this->getFrontendController()->tmpl->flatSetup;
if ((isset($flatSetup) && (is_array($flatSetup)) && (count($flatSetup) > 0))) {
$cache->set(
$cacheIdentifier,
$flatSetup,
array(
'page-' . $this->getFrontendController()->id
),
$cacheLifeTime
);
} else {
$flatSetup = $cache->get($cacheIdentifier);
}

// If flatSetup not available and not cached, generate it!
if (!isset($flatSetup) || !is_array($flatSetup)) {
$this->getFrontendController()->tmpl->generateConfig();
$flatSetup = $this->getFrontendController()->tmpl->flatSetup;
$cache->set(
$cacheIdentifier,
$flatSetup,
array(
'page-' . $this->getFrontendController()->id
),
$cacheLifeTime
);
}

// check if there is a value and return it
Expand Down

0 comments on commit 9e7761e

Please sign in to comment.