/** * The compiled ViewHelper adds two new ViewHelper arguments: __thenClosure and __elseClosure. * These contain closures which are be executed to render the then(), respectively else() case. * * @param string $argumentsVariableName * @param string $renderChildrenClosureVariableName * @param string $initializationPhpCode * @param \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode * @param \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler * @return string * @internal */ public function compile($argumentsVariableName, $renderChildrenClosureVariableName, &$initializationPhpCode, \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode, \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler) { foreach ($syntaxTreeNode->getChildNodes() as $childNode) { if ($childNode instanceof \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode && $childNode->getViewHelperClassName() === 'TYPO3\\CMS\\Fluid\\ViewHelpers\\ThenViewHelper') { $childNodesAsClosure = $templateCompiler->wrapChildNodesInClosure($childNode); $initializationPhpCode .= sprintf('%s[\'__thenClosure\'] = %s;', $argumentsVariableName, $childNodesAsClosure) . chr(10); } if ($childNode instanceof \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode && $childNode->getViewHelperClassName() === 'TYPO3\\CMS\\Fluid\\ViewHelpers\\ElseViewHelper') { $childNodesAsClosure = $templateCompiler->wrapChildNodesInClosure($childNode); $initializationPhpCode .= sprintf('%s[\'__elseClosure\'] = %s;', $argumentsVariableName, $childNodesAsClosure) . chr(10); } } return \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler::SHOULD_GENERATE_VIEWHELPER_INVOCATION; }
/** * The compiled ViewHelper adds two new ViewHelper arguments: __thenClosure and __elseClosure. * These contain closures which are be executed to render the then(), respectively else() case. * * @param string $argumentsVariableName * @param string $renderChildrenClosureVariableName * @param string $initializationPhpCode * @param \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode * @param \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler * @return string * @internal */ public function compile($argumentsVariableName, $renderChildrenClosureVariableName, &$initializationPhpCode, \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode, \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler $templateCompiler) { foreach ($syntaxTreeNode->getChildNodes() as $childNode) { if ($childNode instanceof ViewHelperNode && $childNode->getViewHelperClassName() === ThenViewHelper::class) { $childNodesAsClosure = $templateCompiler->wrapChildNodesInClosure($childNode); $initializationPhpCode .= sprintf('%s[\'__thenClosure\'] = %s;', $argumentsVariableName, $childNodesAsClosure) . LF; } if ($childNode instanceof ViewHelperNode && $childNode->getViewHelperClassName() === ElseViewHelper::class) { $childNodesAsClosure = $templateCompiler->wrapChildNodesInClosure($childNode); $initializationPhpCode .= sprintf('%s[\'__elseClosure\'] = %s;', $argumentsVariableName, $childNodesAsClosure) . LF; } } return sprintf('%s::renderStatic(%s, %s, $renderingContext)', get_class($this), $argumentsVariableName, $renderChildrenClosureVariableName); }