Skip to content

Commit

Permalink
Merge pull request #241 from typo3-themes/analysis-227P9A
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
kaystrobach authored Oct 8, 2022
2 parents a4b50bd + 766022f commit 795bc73
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 69 deletions.
1 change: 0 additions & 1 deletion Classes/Domain/Model/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,3 @@ public function addTypoScriptForFe(&$params, TemplateService &$pObj, $extensions
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,3 @@ public function init(&$params, $pObj)
}
}
}

136 changes: 69 additions & 67 deletions Classes/ViewHelpers/ConstantViewHelper.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?php

namespace KayStrobach\Themes\ViewHelpers;

use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Access constants
*
* @author Thomas Deuling <[email protected]>
* @package themes
*
*
* @deprecated readd constantsviewhelper to ensure compatibility to old themes
*
*
*/
class ConstantViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
class ConstantViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
{

/**
* Initialize arguments.
Expand All @@ -24,76 +26,76 @@ public function initializeArguments()
$this->registerArgument('constant', 'string', 'the constant path', false, '');
}

/**
* Gets a constant
*
* @param string $constant The name of the constant
* @return string Constant-Value
*
* = Examples =
*
* <code title="Example">
* <theme:constant constant="themes.configuration.baseurl" />
* </code>
* <output>
* http://yourdomain.tld/
* (depending on your domain)
* </output>
*/
public function render()
/**
* Gets a constant
*
* @param string $constant The name of the constant
* @return string Constant-Value
*
* = Examples =
*
* <code title="Example">
* <theme:constant constant="themes.configuration.baseurl" />
* </code>
* <output>
* http://yourdomain.tld/
* (depending on your domain)
* </output>
*/
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);
$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 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
);
}
// 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
if ((is_array($flatSetup)) && (array_key_exists($constant, $flatSetup))) {
return $this->getFrontendController()->tmpl->substituteConstants($flatSetup[$constant]);
}
return NULL;
}
// check if there is a value and return it
if ((is_array($flatSetup)) && (array_key_exists($constant, $flatSetup))) {
return $this->getFrontendController()->tmpl->substituteConstants($flatSetup[$constant]);
}
return null;
}

/**
* @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
*/
public function getFrontendController()
/**
* @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
*/
public function getFrontendController()
{
return $GLOBALS['TSFE'];
}
return $GLOBALS['TSFE'];
}
}

0 comments on commit 795bc73

Please sign in to comment.