Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Classes/Middleware/MiddlewareActionAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,6 +127,38 @@
$this->uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
}

/**
* Function to build urls without using $this->uriBuilder.
*
* @param array<string, mixed> $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<string, mixed> $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);

Check failure on line 159 in Classes/Middleware/MiddlewareActionAbstract.php

View workflow job for this annotation

GitHub Actions / phpstan

Cannot call method getRouter() on TYPO3\CMS\Core\Site\Entity\Site|null.
}

protected function getAbsPath(?FileReference $file): string {
if (null == $file) {
return '';
Expand Down
Loading