diff --git a/Build/phpstan.neon b/Build/phpstan.neon index 00e823e0c..ed5e6286b 100644 --- a/Build/phpstan.neon +++ b/Build/phpstan.neon @@ -12,7 +12,6 @@ parameters: ignoreErrors: - identifier: missingType.iterableValue - "#Casting to string something that's already string.#" - - "#^Call to an undefined method TYPO3Fluid\\\\Fluid\\\\Core\\\\Rendering\\\\RenderingContextInterface\\:\\:getRequest\\(\\)\\.$#" paths: - %currentWorkingDirectory%/Classes/ diff --git a/Classes/ViewHelpers/TypoScript/ConstantViewHelper.php b/Classes/ViewHelpers/TypoScript/ConstantViewHelper.php index 605b5d73a..2ea0a9ba5 100644 --- a/Classes/ViewHelpers/TypoScript/ConstantViewHelper.php +++ b/Classes/ViewHelpers/TypoScript/ConstantViewHelper.php @@ -11,10 +11,13 @@ namespace BK2K\BootstrapPackage\ViewHelpers\TypoScript; use BK2K\BootstrapPackage\Utility\TypoScriptUtility; +use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext; use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; /** * ConstantViewHelper + * + * {bk2k:typoScript.constant(constant: 'identifier')} */ class ConstantViewHelper extends AbstractViewHelper { @@ -31,7 +34,15 @@ public function initializeArguments(): void public function render(): string { - $constant = $this->arguments['constant'] ?? ''; - return TypoScriptUtility::getConstants($this->renderingContext->getRequest())[$constant] ?? ''; + $renderingContext = $this->renderingContext; + if ($renderingContext instanceof RenderingContext && $renderingContext->getRequest() !== null) { + $constant = $this->arguments['constant'] ?? ''; + return TypoScriptUtility::getConstants($renderingContext->getRequest())[$constant] ?? ''; + } + + throw new \RuntimeException( + 'ViewHelper bk2k:typoScript.constant needs a request implementing ServerRequestInterface.', + 1639819269 + ); } }