Skip to content

Commit a5b86b6

Browse files
committed
[TASK] Compatibility with v11
1 parent ff7148d commit a5b86b6

File tree

5 files changed

+24
-48
lines changed

5 files changed

+24
-48
lines changed

Classes/Hooks/DataHandlerHook.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use GeorgRinger\Uri2Link\Service\UrlParser;
77
use TYPO3\CMS\Core\DataHandling\DataHandler;
88
use TYPO3\CMS\Core\Utility\GeneralUtility;
9-
use TYPO3\CMS\Core\Utility\StringUtility;
109

1110
class DataHandlerHook
1211
{
@@ -54,8 +53,8 @@ protected function fieldShouldBeProcessed(string $tableName, string $fieldName,
5453
return false;
5554
}
5655

57-
if ($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config']['renderType'] === 'inputLink'
58-
&& (StringUtility::beginsWith($fieldValue, 'http') || StringUtility::beginsWith($fieldValue, '/'))
56+
if (($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config']['renderType'] ?? '') === 'inputLink'
57+
&& (str_starts_with($fieldValue, 'http') || str_starts_with($fieldValue, '/'))
5958
) {
6059
return true;
6160
}

Classes/Service/UrlParser.php

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,33 @@
44
namespace GeorgRinger\Uri2Link\Service;
55

66
use TYPO3\CMS\Core\Context\Context;
7+
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
78
use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException;
8-
use TYPO3\CMS\Core\Http\ImmediateResponseException;
99
use TYPO3\CMS\Core\Http\ServerRequest;
10+
use TYPO3\CMS\Core\Http\ServerRequestFactory;
1011
use TYPO3\CMS\Core\LinkHandling\PageLinkHandler;
1112
use TYPO3\CMS\Core\Routing\PageArguments;
12-
use TYPO3\CMS\Core\Routing\RouteNotFoundException;
1313
use TYPO3\CMS\Core\Routing\SiteMatcher;
1414
use TYPO3\CMS\Core\Routing\SiteRouteResult;
1515
use TYPO3\CMS\Core\SingletonInterface;
1616
use TYPO3\CMS\Core\Site\Entity\Site;
17-
use TYPO3\CMS\Core\Site\Entity\SiteInterface;
1817
use TYPO3\CMS\Core\Utility\GeneralUtility;
1918
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
2019
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
2120
use TYPO3\CMS\Frontend\Service\TypoLinkCodecService;
2221
use TYPO3\CMS\Frontend\Typolink\PageLinkBuilder;
23-
use TYPO3\CMS\Frontend\Typolink\UnableToLinkException;
2422

2523
class UrlParser implements SingletonInterface
2624
{
27-
/** @var PageLinkHandler */
28-
protected $pageLinkHandler;
29-
30-
/** @var TypoLinkCodecService */
31-
protected $typoLinkCodecService;
25+
protected PageLinkHandler $pageLinkHandler;
26+
protected TypoLinkCodecService $typoLinkCodecService;
3227

3328
public function __construct()
3429
{
3530
$this->pageLinkHandler = GeneralUtility::makeInstance(PageLinkHandler::class);
3631
$this->typoLinkCodecService = GeneralUtility::makeInstance(TypoLinkCodecService::class);
3732
}
3833

39-
/**
40-
* @param string $uri
41-
* @return string
42-
* @throws UnableToLinkException
43-
* @throws RouteNotFoundException
44-
*/
4534
public function parse(string $uri): string
4635
{
4736
$uriParts = $this->typoLinkCodecService->decode($uri);
@@ -59,11 +48,8 @@ public function parse(string $uri): string
5948
$parameters = $this->buildLinkParameters($routeResult, $pageArguments);
6049

6150
if ($this->validateUrl($uri, $parameters, $site)) {
62-
$uriParts['url'] = $this->pageLinkHandler->asString($parameters);;
51+
$uriParts['url'] = $this->pageLinkHandler->asString($parameters);
6352
return $this->typoLinkCodecService->encode($uriParts);
64-
} else {
65-
// print_r($parameters);
66-
// die;
6753
}
6854

6955
return $uri;
@@ -90,26 +76,16 @@ protected function buildLinkParameters(SiteRouteResult $routeResult, PageArgumen
9076
return $parameters;
9177
}
9278

93-
/**
94-
* @param string $uri
95-
* @param array $parameters
96-
* @param Site $site
97-
* @return bool
98-
* @throws UnableToLinkException
99-
*/
10079
protected function validateUrl(string $uri, array $parameters, Site $site): bool
10180
{
102-
10381
$queryParams = [];
10482

10583
$controller = $this->bootFrontendController($site, $queryParams);
10684
$pageLinkBuilder = GeneralUtility::makeInstance(PageLinkBuilder::class, $controller->cObj, $controller);
10785
$newUrlResult = $pageLinkBuilder->build($parameters, 'fake', '', []);
108-
if ($newUrlResult[0] === $uri) {
109-
return true;
110-
}
86+
$newUrlResultAbsolute = $pageLinkBuilder->build($parameters, 'fake', '', ['forceAbsoluteUrl' => true]);
11187

112-
return false;
88+
return $newUrlResult->getUrl() === $uri || $newUrlResultAbsolute->getUrl() === $uri;
11389
}
11490

11591
/**
@@ -129,24 +105,28 @@ protected function validateUrl(string $uri, array $parameters, Site $site): bool
129105
* @param array $queryParams
130106
* @return TypoScriptFrontendController
131107
* @throws ServiceUnavailableException
132-
* @throws ImmediateResponseException
133108
*/
134109
protected function bootFrontendController(Site $site, array $queryParams): TypoScriptFrontendController
135110
{
136-
$pageId = $site ? $site->getRootPageId() : 0;
111+
$originalRequest = $GLOBALS['TYPO3_REQUEST'] ?? ServerRequestFactory::fromGlobals();
137112
$controller = GeneralUtility::makeInstance(
138113
TypoScriptFrontendController::class,
139114
GeneralUtility::makeInstance(Context::class),
140115
$site,
141116
$site->getDefaultLanguage(),
142-
new PageArguments((int)$pageId, '0', [])
117+
new PageArguments($site->getRootPageId(), '0', []),
118+
GeneralUtility::makeInstance(FrontendUserAuthentication::class)
143119
);
144-
$controller->fe_user = GeneralUtility::makeInstance(FrontendUserAuthentication::class);;
145-
$controller->fetch_the_id();
120+
$controller->determineId($originalRequest);
146121
$controller->calculateLinkVars($queryParams);
147122
$controller->getConfigArray();
148-
$controller->settingLanguage();
149-
$controller->newCObj();
123+
$controller->newCObj($originalRequest);
124+
if (!isset($GLOBALS['TSFE']) || !$GLOBALS['TSFE'] instanceof TypoScriptFrontendController) {
125+
$GLOBALS['TSFE'] = $controller;
126+
}
127+
if (!$GLOBALS['TSFE']->sys_page instanceof PageRepository) {
128+
$GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance(PageRepository::class);
129+
}
150130
return $controller;
151131
}
152132
}

composer.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"GPL-2.0-or-later"
2222
],
2323
"require": {
24-
"typo3/cms-core": "^9.5.9|| ^10.0",
25-
"typo3/cms-frontend": "^9.5.9|| ^10.0"
24+
"typo3/cms-core": "^11.5.34 || ^12.4.10",
25+
"typo3/cms-frontend": "^11.5.34 || ^12.4.10"
2626
},
2727
"autoload": {
2828
"psr-4": {
@@ -34,9 +34,6 @@
3434
"GeorgRinger\\Uri2Link\\Tests\\": "Tests"
3535
}
3636
},
37-
"replace": {
38-
"typo3-ter/uri2link": "self.version"
39-
},
4037
"extra": {
4138
"typo3/cms": {
4239
"extension-key": "uri2link"

ext_emconf.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
'author_email' => '',
99
'state' => 'beta',
1010
'clearCacheOnLoad' => true,
11-
'version' => '0.1.0',
11+
'version' => '0.2.0',
1212
'constraints' => [
1313
'depends' => [
14-
'typo3' => '9.5.0-10.2.99',
14+
'typo3' => '11.5.33-12.4.99',
1515
],
1616
'conflicts' => [],
1717
'suggests' => [],

0 commit comments

Comments
 (0)