2024-05-30 14:01:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace DigiComp\FluidCurrentControllerExpression;
|
|
|
|
|
|
|
|
use Neos\FluidAdaptor\Core\Rendering\RenderingContext;
|
|
|
|
use Neos\Utility\ObjectAccess;
|
|
|
|
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\AbstractExpressionNode;
|
|
|
|
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\Expression\ExpressionNodeInterface;
|
|
|
|
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
|
|
|
|
|
|
|
class CurrentControllerExpressionNode extends AbstractExpressionNode implements ExpressionNodeInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* note: this could be readonly in PHP8
|
|
|
|
* @var string
|
|
|
|
*/
|
2024-05-30 15:12:49 +02:00
|
|
|
public static string $detectionExpression = '/\{#currentController\.([a-zA-Z0-9\.]+)\}/';
|
2024-05-30 14:01:25 +02:00
|
|
|
|
|
|
|
public static function evaluateExpression(RenderingContextInterface $renderingContext, $expression, array $matches)
|
|
|
|
{
|
|
|
|
if ($renderingContext instanceof RenderingContext) {
|
|
|
|
$propertyToReturn = $matches[1];
|
|
|
|
if (
|
|
|
|
\in_array(
|
|
|
|
$propertyToReturn,
|
|
|
|
['actionName', 'name', 'objectName', 'packageKey', 'subpackageKey'],
|
|
|
|
true
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
$propertyToReturn = 'controller' . \ucfirst($propertyToReturn);
|
|
|
|
}
|
2024-05-30 15:12:49 +02:00
|
|
|
return ObjectAccess::getPropertyPath(
|
2024-05-30 14:01:25 +02:00
|
|
|
$renderingContext->getControllerContext()->getRequest(),
|
|
|
|
$propertyToReturn
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|