‪TYPO3CMS  9.5
ModuleLinkViewHelper.php
Go to the documentation of this file.
1 <?php
2 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 
21 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
24 
43 class ‪ModuleLinkViewHelper extends AbstractViewHelper
44 {
45  use CompileWithRenderStatic;
46 
50  public function ‪initializeArguments()
51  {
52  $this->registerArgument('route', 'string', 'The route to link to', true);
53  $this->registerArgument('arguments', 'array', 'Additional link arguments', false, []);
54  $this->registerArgument('query', 'string', 'Additional link arguments as string');
55  $this->registerArgument('currentUrlParameterName', 'string', 'Add current url as given parameter');
56  }
57 
66  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
67  {
68  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
69  $parameters = $arguments['arguments'];
70  if ($arguments['query'] !== null) {
71  ‪ArrayUtility::mergeRecursiveWithOverrule($parameters, GeneralUtility::explodeUrl2Array($arguments['query']));
72  }
73  if ($arguments['currentUrlParameterName'] !== null) {
74  $parameters[$arguments['currentUrlParameterName']] = GeneralUtility::getIndpEnv('REQUEST_URI');
75  }
76 
77  return (string)$uriBuilder->buildUriFromRoute($arguments['route'], $parameters);
78  }
79 }
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Backend\ViewHelpers
Definition: AvatarViewHelper.php:2
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45