Hi I need some support regarding frontend url generation inside building REST API. I'm using restler for the API. I could generate the url with
$site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($arguments['pageUid']);
return (string)$site->getRouter()->generateUri($arguments['pageUid'],$queryStrings);
But the problem is it is not building the extension parameters using the routing configuration. The url works as expected.
Update: To get more understanding: I added the info more. This is same like generating a frontend url in backend, scheduler task or command controller. Where GLOBALS['TSFE'] not available.
I use the above function like this.
public function generateUrl(
int $pageId,
array $arguments,
bool $absolute
): string
{
$site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($pageId);
if (empty($site->getBase()->getHost()) || empty($site->getBase()->getScheme())) {
throw new \RuntimeException(
"Site " . $site->getIdentifier() . ' does not have proper schema or host set. Thus not usable in cli context.',
1648736865
);
}
$uri = $site
->getRouter()
->generateUri(
$pageId,
$arguments,
'',
PageRouter::ABSOLUTE_URL
);
if (empty($uri->getHost()) || empty($uri->getScheme())) {
throw new \RuntimeException(
'Build uri did not have proper schema or host set. Thus not usable in cli context. ' . (string)$uri,
1648736938
);
}
if (!$absolute) {
return $uri->getPath() . (!empty($uri->getQuery()) ? '?' . $uri->getQuery() : '');
}
return (string)$uri;
}
Any Idea ?
if you have PageUid already and Arguments then you can try building URI with UriBuilder of TYPO3.