[FEATURE] Add more arguments to the ModuleLinkViewHelper 38/55838/6
authorGeorg Ringer <georg.ringer@gmail.com>
Tue, 20 Feb 2018 18:26:42 +0000 (19:26 +0100)
committerSusanne Moog <susanne.moog@typo3.org>
Sat, 12 May 2018 09:23:24 +0000 (11:23 +0200)
Improve the ModuleLinkViewHelper by providing arguments as string
and the possibility to add a returnUrl.

Resolves: #83983
Releases: master
Change-Id: I23ff113fd499215832d8d97acff97a0ac05be2b3
Reviewed-on: https://review.typo3.org/55838
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/backend/Classes/ViewHelpers/ModuleLinkViewHelper.php
typo3/sysext/core/Documentation/Changelog/master/Feature-83983-ImprovedModuleLinkViewHelper.rst [new file with mode: 0644]

index 03b955f..02ec6b2 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Backend\ViewHelpers;
  */
 
 use TYPO3\CMS\Backend\Routing\UriBuilder;
+use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
@@ -35,6 +36,8 @@ class ModuleLinkViewHelper extends AbstractViewHelper
     {
         $this->registerArgument('route', 'string', 'The route to link to', true);
         $this->registerArgument('arguments', 'array', 'Additional link arguments', false, []);
+        $this->registerArgument('query', 'string', 'Additional link arguments as string');
+        $this->registerArgument('currentUrlParameterName', 'string', 'Add current url as given parameter');
     }
 
     /**
@@ -48,6 +51,14 @@ class ModuleLinkViewHelper extends AbstractViewHelper
     public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
     {
         $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
-        return (string)$uriBuilder->buildUriFromRoute($arguments['route'], $arguments['arguments']);
+        $parameters = $arguments['arguments'];
+        if ($arguments['query'] !== null) {
+            ArrayUtility::mergeRecursiveWithOverrule($parameters, GeneralUtility::explodeUrl2Array($arguments['query']));
+        }
+        if ($arguments['currentUrlParameterName'] !== null) {
+            $parameters[$arguments['currentUrlParameterName']] = GeneralUtility::getIndpEnv('REQUEST_URI');
+        }
+
+        return (string)$uriBuilder->buildUriFromRoute($arguments['route'], $parameters);
     }
 }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-83983-ImprovedModuleLinkViewHelper.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-83983-ImprovedModuleLinkViewHelper.rst
new file mode 100644 (file)
index 0000000..df179d6
--- /dev/null
@@ -0,0 +1,32 @@
+.. include:: ../../Includes.txt
+
+===============================================
+Feature: #83983 - Improved ModuleLinkViewHelper
+===============================================
+
+See :issue:`83983`
+
+Description
+===========
+
+The class :php:`\TYPO3\CMS\Backend\ViewHelpers\ModuleLinkViewHelper` has been improved by
+providing two additional arguments:
+
+- `query`: Allow defining query parameters also as string
+- `currentUrlParameterName`: The given argument is filled with the current URL
+
+With this change it is easily possible to migrate existing custom backend route viewhelpers to this one viewhelper.
+
+For example:
+
+Before::
+
+   {bu:editRecord(parameters: 'edit[be_users][{backendUser.uid}]=edit&returnUrl={returnUrl}')}
+
+After ::
+
+   {be:moduleLink(route: 'record_edit', query: 'edit[be_users][{backendUser.uid}]=edit&returnUrl={returnUrl}')}
+
+... and the editRecord ViewHelper of be_user could be deprecated.
+
+.. index:: Backend, ext:backend