Skip to content

Commit 703ca3c

Browse files
committed
[FEATURE] Convert links set in RTE modal
1 parent 4724518 commit 703ca3c

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace GeorgRinger\Uri2Link\Controller;
5+
6+
7+
use GeorgRinger\Uri2Link\Service\UrlParser;
8+
use Psr\Http\Message\ServerRequestInterface;
9+
use TYPO3\CMS\Core\Http\JsonResponse;
10+
use TYPO3\CMS\Core\Utility\GeneralUtility;
11+
12+
class AjaxController
13+
{
14+
15+
public function checkAction(ServerRequestInterface $request): JsonResponse
16+
{
17+
$uri = $request->getQueryParams()['uri'];
18+
$response = [];
19+
$parser = GeneralUtility::makeInstance(UrlParser::class);
20+
21+
try {
22+
$newValue = $parser->parse($uri);
23+
if ($newValue !== $uri) {
24+
$response['transformed'] = $newValue;
25+
$response['status'] = true;
26+
}
27+
} catch (\Exception $exception) {
28+
$response['false'] = true;
29+
$response['message'] = $exception->getMessage();
30+
}
31+
return new JsonResponse($response);
32+
}
33+
34+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace GeorgRinger\Uri2Link\LinkHandling;
5+
6+
use Psr\Http\Message\ServerRequestInterface;
7+
use TYPO3\CMS\Core\Page\PageRenderer;
8+
use TYPO3\CMS\Core\Utility\GeneralUtility;
9+
10+
class UrlLinkHandler extends \TYPO3\CMS\Recordlist\LinkHandler\UrlLinkHandler
11+
{
12+
public function render(ServerRequestInterface $request)
13+
{
14+
GeneralUtility::makeInstance(PageRenderer::class)->loadRequireJsModule('TYPO3/CMS/Uri2link/BetterUrlLinkHandler');
15+
$this->view->assign('url', !empty($this->linkParts) ? $this->linkParts['url'] : '');
16+
return $this->view->render('Url');
17+
}
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return [
4+
'uri2link_check' => [
5+
'path' => '/uri2link/check',
6+
'target' => \GeorgRinger\Uri2Link\Controller\AjaxController::class . '::checkAction'
7+
],
8+
];
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* This file is part of the TYPO3 CMS project.
3+
*
4+
* It is free software; you can redistribute it and/or modify it under
5+
* the terms of the GNU General Public License, either version 2
6+
* of the License, or any later version.
7+
*
8+
* For the full copyright and license information, please read the
9+
* LICENSE.txt file that was distributed with this source code.
10+
*
11+
* The TYPO3 project - inspiring people to share!
12+
*/
13+
14+
/**
15+
* Module: TYPO3/CMS/Recordlist/UrlLinkHandler
16+
* URL link interaction
17+
*/
18+
define(['jquery', 'TYPO3/CMS/Recordlist/LinkBrowser'], function ($, LinkBrowser) {
19+
'use strict';
20+
21+
/**
22+
*
23+
* @type {{}}
24+
* @exports TYPO3/CMS/Recordlist/UrlLinkHandler
25+
*/
26+
var UrlLinkHandler = {};
27+
28+
/**
29+
*
30+
* @param {Event} event
31+
*/
32+
UrlLinkHandler.link = function (event) {
33+
event.preventDefault();
34+
35+
var value = $(this).find('[name="lurl"]').val();
36+
if (value === '') {
37+
return;
38+
}
39+
40+
$.ajax({
41+
url: TYPO3.settings.ajaxUrls['uri2link_check'],
42+
data: {
43+
uri: value
44+
}
45+
}).done(function (data) {
46+
47+
if (data.transformed) {
48+
LinkBrowser.finalizeFunction(data.transformed);
49+
} else {
50+
LinkBrowser.finalizeFunction(value);
51+
}
52+
}).fail(function (data) {
53+
LinkBrowser.finalizeFunction(value);
54+
});
55+
};
56+
57+
$(function () {
58+
$('#lurlform').on('submit', UrlLinkHandler.link);
59+
});
60+
61+
return UrlLinkHandler;
62+
});
63+
64+

ext_localconf.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,12 @@
22

33
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['uri2link'] =
44
\GeorgRinger\Uri2Link\Hooks\DataHandlerHook::class;
5+
6+
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('
7+
TCEMAIN.linkHandler {
8+
url {
9+
handler = GeorgRinger\Uri2Link\LinkHandling\UrlLinkHandler
10+
}
11+
12+
}
13+
');

0 commit comments

Comments
 (0)