59 lines
2.2 KiB
PHP
59 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DigiComp\FluidRenderFunctions\FormExtensions;
|
|
|
|
use DigiComp\FluidRenderFunctions\InvokeRenderFunctionInterface;
|
|
use DigiComp\FluidRenderFunctions\Utils\RenderableProxy;
|
|
use DigiComp\FluidRenderFunctions\ViewHelpers\RegisterRenderFunctionViewHelper;
|
|
use Neos\Flow\Annotations as Flow;
|
|
use Neos\Flow\Aop\JoinPointInterface;
|
|
use Neos\FluidAdaptor\ViewHelpers\Form\TextfieldViewHelper;
|
|
|
|
/**
|
|
* @Flow\Aspect
|
|
*/
|
|
class TextfieldAspect extends TextfieldViewHelper
|
|
{
|
|
/**
|
|
* @Flow\After("setting(DigiComp.FluidRenderFunctions.enableAspects.textfield) && method(Neos\FluidAdaptor\ViewHelpers\Form\TextfieldViewHelper->initializeArguments())")
|
|
*/
|
|
public function introduceRenderFuncArgument(JoinPointInterface $joinPoint): void
|
|
{
|
|
$proxy = $joinPoint->getProxy();
|
|
if (!($proxy instanceof TextfieldViewHelper)) {
|
|
return;
|
|
}
|
|
$proxy->registerArgument('renderFunction', 'string', 'callabe to use to render single object');
|
|
}
|
|
|
|
/**
|
|
* @Flow\Around("setting(DigiComp.FluidRenderFunctions.enableAspects.textfield) && method(Neos\FluidAdaptor\ViewHelpers\Form\TextfieldViewHelper->getValueAttribute())")
|
|
*/
|
|
public function applyRenderFunctionToValue(JoinPointInterface $joinPoint)
|
|
{
|
|
$proxy = $joinPoint->getProxy();
|
|
if (!($proxy instanceof TextfieldViewHelper)) {
|
|
return;
|
|
}
|
|
if (!isset($proxy->arguments['renderFunction'])) {
|
|
return $joinPoint->getAdviceChain()->proceed($joinPoint);
|
|
}
|
|
$renderFunction = $proxy->viewHelperVariableContainer->get(
|
|
RegisterRenderFunctionViewHelper::class,
|
|
$proxy->arguments['renderFunction']
|
|
);
|
|
if (!($renderFunction instanceof InvokeRenderFunctionInterface)) {
|
|
throw new \InvalidArgumentException(
|
|
'render function with name "' . $proxy->arguments['renderFunction'] . '" has not been registered.',
|
|
1717293038
|
|
);
|
|
}
|
|
$originalObject = $joinPoint->getAdviceChain()->proceed($joinPoint);
|
|
if (\is_object($originalObject)) {
|
|
return new RenderableProxy($renderFunction, $originalObject);
|
|
}
|
|
return $originalObject;
|
|
}
|
|
}
|