‪TYPO3CMS  10.4
ModuleLinkViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
26 
45 class ‪ModuleLinkViewHelper extends AbstractViewHelper
46 {
47  use CompileWithRenderStatic;
48 
52  public function ‪initializeArguments()
53  {
54  $this->registerArgument('route', 'string', 'The route to link to', true);
55  $this->registerArgument('arguments', 'array', 'Additional link arguments', false, []);
56  $this->registerArgument('query', 'string', 'Additional link arguments as string');
57  $this->registerArgument('currentUrlParameterName', 'string', 'Add current url as given parameter');
58  }
59 
68  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
69  {
70  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
71  $parameters = $arguments['arguments'];
72  if ($arguments['query'] !== null) {
73  ‪ArrayUtility::mergeRecursiveWithOverrule($parameters, GeneralUtility::explodeUrl2Array($arguments['query']));
74  }
75  if ($arguments['currentUrlParameterName'] !== null) {
76  $parameters[$arguments['currentUrlParameterName']] = GeneralUtility::getIndpEnv('REQUEST_URI');
77  }
78 
79  return (string)$uriBuilder->buildUriFromRoute($arguments['route'], $parameters);
80  }
81 }
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:654
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\ViewHelpers
Definition: ArrayBrowserViewHelper.php:18
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46