DigiComp.FluidRenderFunctions/Classes/ViewHelpers/RegisterRenderFunctionViewHelper.php
Ferdinand Kuhl 0de901d45c
Some checks failed
ci/woodpecker/push/code-style Pipeline was successful
ci/woodpecker/push/functional-tests/1 Pipeline failed
ci/woodpecker/push/functional-tests/2 Pipeline failed
ci/woodpecker/push/functional-tests/3 Pipeline failed
ci/woodpecker/push/functional-tests/4 Pipeline failed
First working version
2024-06-01 23:15:35 +02:00

54 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace DigiComp\FluidRenderFunctions\ViewHelpers;
use DigiComp\FluidRenderFunctions\Utils\NodeRenderTransfer;
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\RootNode;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
class RegisterRenderFunctionViewHelper extends AbstractViewHelper
{
/**
* @throws \Neos\FluidAdaptor\Core\ViewHelper\Exception
*/
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('as', 'string', 'Name of the registered render function', false, 'renderFunc');
$this->registerArgument(
'subjectName',
'string',
'Name of the argument passed to render function',
false,
'subject'
);
}
public function compile(
$argumentsName,
$closureName,
&$initializationPhpCode,
ViewHelperNode $node,
TemplateCompiler $compiler
) {
// we disable compiling, because we will need access to the AST, which is not available if compiled
// a cool improvement would be to drop the need to the AST and so become compilable
$compiler->disable();
return "''";
}
public function render(): string
{
$transferNode = new RootNode();
foreach ($this->childNodes as $childNode) {
$transferNode->addChildNode($childNode);
}
$this->renderingContext->getVariableProvider()
->add($this->arguments['as'], new NodeRenderTransfer($transferNode, $this->arguments['subjectName']));
return '';
}
}