‪TYPO3CMS  9.5
TypolinkViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
23 
58 class ‪TypolinkViewHelper extends AbstractViewHelper
59 {
60  use CompileWithRenderStatic;
61 
65  public function ‪initializeArguments()
66  {
67  $this->registerArgument('parameter', 'string', 'stdWrap.typolink style parameter string', true);
68  $this->registerArgument('additionalParams', 'string', 'stdWrap.typolink additionalParams', false, '');
69  $this->registerArgument('useCacheHash', 'bool', '', false, false);
70  $this->registerArgument('addQueryString', 'bool', '', false, false);
71  $this->registerArgument('addQueryStringMethod', 'string', '', false, 'GET');
72  $this->registerArgument('addQueryStringExclude', 'string', '', false, '');
73  $this->registerArgument('absolute', 'bool', 'Ensure the resulting URL is an absolute URL', false, false);
74  }
75 
83  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
84  {
85  $parameter = $arguments['parameter'];
86  $additionalParams = $arguments['additionalParams'];
87  $useCacheHash = $arguments['useCacheHash'];
88  $addQueryString = $arguments['addQueryString'];
89  $addQueryStringMethod = $arguments['addQueryStringMethod'];
90  $addQueryStringExclude = $arguments['addQueryStringExclude'];
91  $absolute = $arguments['absolute'];
92 
93  $content = '';
94  if ($parameter) {
95  $contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
96  $content = $contentObject->typoLink_URL(
97  [
98  'parameter' => self::createTypolinkParameterFromArguments($parameter, $additionalParams),
99  'useCacheHash' => $useCacheHash,
100  'addQueryString' => $addQueryString,
101  'addQueryString.' => [
102  'method' => $addQueryStringMethod,
103  'exclude' => $addQueryStringExclude
104  ],
105  'forceAbsoluteUrl' => $absolute
106  ]
107  );
108  }
109 
110  return $content;
111  }
112 
121  protected static function ‪createTypolinkParameterFromArguments($parameter, $additionalParameters = '')
122  {
123  $typoLinkCodec = GeneralUtility::makeInstance(TypoLinkCodecService::class);
124  $typolinkConfiguration = $typoLinkCodec->decode($parameter);
125 
126  // Combine additionalParams
127  if ($additionalParameters) {
128  $typolinkConfiguration['additionalParams'] .= $additionalParameters;
129  }
130 
131  return $typoLinkCodec->encode($typolinkConfiguration);
132  }
133 }
‪TYPO3\CMS\Fluid\ViewHelpers\Uri
Definition: ActionViewHelper.php:2
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:91
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45