All checks were successful
ci/woodpecker/push/code-style Pipeline was successful
ci/woodpecker/push/functional-tests/1 Pipeline was successful
ci/woodpecker/push/functional-tests/2 Pipeline was successful
ci/woodpecker/push/functional-tests/3 Pipeline was successful
ci/woodpecker/push/functional-tests/4 Pipeline was successful
55 lines
1.8 KiB
PHP
55 lines
1.8 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);
|
|
}
|
|
$renderer = new NodeRenderTransfer($transferNode, $this->arguments['subjectName']);
|
|
$this->renderingContext->getViewHelperVariableContainer()
|
|
->add(static::class, $this->arguments['as'], $renderer);
|
|
return '';
|
|
}
|
|
}
|