Skip to content

Commit

Permalink
[TASK] Cleanup constant viewhelper
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminkott committed Oct 10, 2024
1 parent 901dfb4 commit 376bf5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 0 additions & 1 deletion Build/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
15 changes: 13 additions & 2 deletions Classes/ViewHelpers/TypoScript/ConstantViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
);
}
}

0 comments on commit 376bf5f

Please sign in to comment.