Skip to content

Commit c0da0ed

Browse files
author
Konrad Michalik
authored
Merge pull request #45 from xima-media/redirect-edit
feat: extend UrlUtility for dynamic URL building with redirect option
2 parents c9bb87e + 21eccd8 commit c0da0ed

5 files changed

Lines changed: 43 additions & 3 deletions

File tree

Classes/Service/MenuGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Xima\XimaTypo3FrontendEdit\Event\FrontendEditDropdownModifyEvent;
1919
use Xima\XimaTypo3FrontendEdit\Template\Component\Button;
2020
use Xima\XimaTypo3FrontendEdit\Utility\ContentUtility;
21+
use Xima\XimaTypo3FrontendEdit\Utility\UrlUtility;
2122

2223
final class MenuGenerator
2324
{
@@ -130,7 +131,7 @@ public function getDropdown(int $pid, string $returnUrl, int $languageUid, array
130131
'edit',
131132
ButtonType::Link,
132133
label: $contentElement['CType'] === 'list' ? 'LLL:EXT:xima_typo3_frontend_edit/Resources/Private/Language/locallang.xlf:edit_plugin' : 'LLL:EXT:xima_typo3_frontend_edit/Resources/Private/Language/locallang.xlf:edit_content_element',
133-
url: GeneralUtility::makeInstance(UriBuilder::class)->buildUriFromRoute(
134+
url: UrlUtility::buildUrl(
134135
'record_edit',
135136
[
136137
'edit' => [
@@ -141,8 +142,7 @@ public function getDropdown(int $pid, string $returnUrl, int $languageUid, array
141142
],
142143
'returnUrl' => $returnUrlAnchor,
143144
]
144-
)->__toString()
145-
. '&tx_ximatypo3frontendedit', // add custom parameter to identify the request and render the save and close button in the edit form
145+
) . '&tx_ximatypo3frontendedit', // add custom parameter to identify the request and render the save and close button in the edit form
146146
icon: $contentElement['CType'] === 'list' ? 'content-plugin' : 'content-textpic'
147147
);
148148
$this->processNewButton(

Classes/Utility/UrlUtility.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
namespace Xima\XimaTypo3FrontendEdit\Utility;
66

7+
use TYPO3\CMS\Backend\Routing\RouteRedirect;
8+
use TYPO3\CMS\Backend\Routing\UriBuilder;
9+
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
710
use TYPO3\CMS\Core\Utility\GeneralUtility;
811
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
12+
use Xima\XimaTypo3FrontendEdit\Configuration;
913

1014
class UrlUtility
1115
{
@@ -25,4 +29,19 @@ public static function getUrl(int $pageId, ?int $languageUid = 0, bool $forceAbs
2529

2630
return $contentObjectRenderer->typoLink_URL($typolinkConfiguration);
2731
}
32+
33+
public static function buildUrl(string $route, array $parameters): string
34+
{
35+
$useRedirect = false;
36+
$extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class);
37+
if (isset($extensionConfiguration->get(Configuration::EXT_KEY)['useRedirect']) && $extensionConfiguration->get(Configuration::EXT_KEY)['useRedirect']) {
38+
$useRedirect = true;
39+
}
40+
41+
if ($useRedirect) {
42+
return GeneralUtility::makeInstance(UriBuilder::class)->buildUriWithRedirect('main', [], RouteRedirect::create($route, $parameters))->__toString();
43+
}
44+
45+
return GeneralUtility::makeInstance(UriBuilder::class)->buildUriFromRoute($route, $parameters)->__toString();
46+
}
2847
}

Documentation/Configuration/ExtensionConfiguration.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,15 @@ The extension currently provides the following configuration options:
4242
:Default: 0
4343

4444
This mode will disable the menu dropdown and use the edit icon button directly as edit link instead
45+
46+
.. _extconf-useRedirect:
47+
48+
.. confval:: Redirect
49+
:type: boolean
50+
:Default: 0
51+
52+
Use the redirect option to redirect the edit links, so the full TYPO3 backend is loaded instead of only the edit form
53+
54+
.. warning::
55+
This option is useful if you want to use the full TYPO3 backend, e.g. language switch or modal popups for for inline group type.
56+
But keep in mind, that with this option the return to the frontend using the "close" button will not work anymore.

Documentation/FAQ/Index.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,10 @@ After closing the edit form will I redirected to the wrong frontend location, e.
4444
=======================================
4545

4646
This could be caused by a strict referer header in your request. If the return url could not be determined correctly, you can force the url generation by pid and language in the extension setting: :code:`forceReturnUrlGeneration`.
47+
48+
.. rst-class:: panel panel-default
49+
50+
I can't change the language within a content element.
51+
=======================================
52+
53+
This is a TYPO3 backend limitation. The reduced edit form frame does not support the language switch. Use the :ref:`redirect <extconf-useRedirect>` configuration in the extension settings to open the edit form within the full TYPO3 backend context, which supports the language switch.

ext_conf_template.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ forceReturnUrlGeneration = 0
66
linkTargetBlank = 0
77
# cat=basic//103; type=boolean; label=Simple mode: This mode will disable the menu dropdown and use the edit icon button directly as edit link instead
88
simpleMode = 0
9+
# cat=basic//104; type=boolean; label=Redirect: Use the redirect option to redirect the edit links, so the full TYPO3 backend is loaded instead of only the edit form
10+
useRedirect = 0

0 commit comments

Comments
 (0)