diff --git a/Classes/Middleware/MiddlewareActionAbstract.php b/Classes/Middleware/MiddlewareActionAbstract.php index 89abd4c..e317fb5 100644 --- a/Classes/Middleware/MiddlewareActionAbstract.php +++ b/Classes/Middleware/MiddlewareActionAbstract.php @@ -6,6 +6,7 @@ namespace JAKOTA\Typo3ToolBox\Middleware; use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Message\UriInterface; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\LanguageAspect; use TYPO3\CMS\Core\Context\UserAspect; @@ -126,6 +127,38 @@ public function __construct(ServerRequestInterface $request, $pathParams) { $this->uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); } + /** + * Function to build urls without using $this->uriBuilder. + * + * @param array $additionalGetParams additional GET parameters + * @param null|string $extensionName Extension name without underscores. Eg. 'myextension' + * @param null|string $pluginName Plugin name with underscores. Eg. 'news_show' or 'records_list' + * @param null|string $actionName Action name (the 'show' of 'news_show') + * @param null|string $controllerName Name of the controller. Eg. 'News' or 'Record' + * @param array $actionArguments Additional arguments needed for the Action. Eg. [newsId => 123, ...] + */ + protected function buildUri(int $pageId, array $additionalGetParams = [], ?string $extensionName = null, ?string $pluginName = null, ?string $actionName = null, ?string $controllerName = null, array $actionArguments = []): ?UriInterface { + if (null === ($this->site?->getRouter() ?? null)) { + return null; + } + + $arguments = [ + ...$additionalGetParams, + ]; + + if (null !== $extensionName && null !== $pluginName && null !== $actionName && null !== $controllerName) { + $arguments = [ + strtolower("tx_{$extensionName}_{$pluginName}") => [ + 'action' => $actionName, + 'controller' => $controllerName, + ...$actionArguments, + ], + ]; + } + + return $this->site->getRouter()->generateUri($pageId, $arguments); + } + protected function getAbsPath(?FileReference $file): string { if (null == $file) { return '';