Created
July 21, 2016 13:44
-
-
Save smichaelsen/6d76c7afaf050741441dd083f6e29939 to your computer and use it in GitHub Desktop.
Custom UncacheViewHelper that fixes https://github.com/FluidTYPO3/vhs/issues/1075
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Schaefertours\PackageSchaefertours\ViewHelpers\Render; | |
use FluidTYPO3\Vhs\View\UncacheTemplateView; | |
use TYPO3\CMS\Core\Utility\GeneralUtility; | |
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; | |
use TYPO3\CMS\Extbase\Utility\ArrayUtility; | |
/** | |
* Fixes https://github.com/FluidTYPO3/vhs/issues/1075 and can be removed and replaced with the original UncacheViewHelper once | |
* the issue is resolved. | |
*/ | |
class UncacheViewHelper extends \FluidTYPO3\Vhs\ViewHelpers\Render\UncacheViewHelper | |
{ | |
/** | |
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface | |
*/ | |
protected $configurationManager; | |
/** | |
* @param ConfigurationManagerInterface $configurationManager | |
*/ | |
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager) | |
{ | |
$this->configurationManager = $configurationManager; | |
} | |
/** | |
* @return string | |
*/ | |
public function render() | |
{ | |
$partialArguments = $this->arguments['arguments']; | |
if (FALSE === is_array($partialArguments)) { | |
$partialArguments = array(); | |
} | |
if (FALSE === isset($partialArguments['settings']) && TRUE === $this->templateVariableContainer->exists('settings')) { | |
$partialArguments['settings'] = $this->templateVariableContainer->get('settings'); | |
} | |
$substKey = 'INT_SCRIPT.' . $GLOBALS['TSFE']->uniqueHash(); | |
$content = '<!--' . $substKey . '-->'; | |
$templateView = GeneralUtility::makeInstance(UncacheTemplateView::class); | |
$partialRootPaths = $this->getPartialRootPaths(); | |
if (!empty($partialRootPaths)) { | |
$templateView->setPartialRootPaths($partialRootPaths); | |
} | |
$GLOBALS['TSFE']->config['INTincScript'][$substKey] = array( | |
'type' => 'POSTUSERFUNC', | |
'cObj' => serialize($templateView), | |
'postUserFunc' => 'render', | |
'conf' => array( | |
'partial' => $this->arguments['partial'], | |
'section' => $this->arguments['section'], | |
'arguments' => $partialArguments, | |
'controllerContext' => $this->renderingContext->getControllerContext() | |
), | |
'content' => $content | |
); | |
return $content; | |
} | |
/** | |
* @return array | |
*/ | |
protected function getPartialRootPaths() | |
{ | |
$this->configurationManager->setConfiguration(['extensionName' => $this->controllerContext->getRequest()->getControllerExtensionName()]); | |
$extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration( | |
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK | |
); | |
$setting = 'partialRootPaths'; | |
$values = []; | |
if ( | |
!empty($extbaseFrameworkConfiguration['view'][$setting]) | |
&& is_array($extbaseFrameworkConfiguration['view'][$setting]) | |
) { | |
$values = ArrayUtility::sortArrayWithIntegerKeys($extbaseFrameworkConfiguration['view'][$setting]); | |
$values = array_reverse($values, true); | |
} | |
return $values; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment