TYPO3 CMS  TYPO3_8-7
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  */
22 
48 {
50 
54  public function initializeArguments()
55  {
56  parent::initializeArguments();
57  $this->registerArgument('parameter', 'string', 'stdWrap.typolink style parameter string', true);
58  $this->registerArgument('additionalParams', 'string', 'stdWrap.typolink additionalParams', false, '');
59  $this->registerArgument('useCacheHash', 'bool', '', false, false);
60  $this->registerArgument('addQueryString', 'bool', '', false, false);
61  $this->registerArgument('addQueryStringMethod', 'string', '', false, 'GET');
62  $this->registerArgument('addQueryStringExclude', 'string', '', false, '');
63  $this->registerArgument('absolute', 'bool', 'Ensure the resulting URL is an absolute URL', false, false);
64  }
65 
73  public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
74  {
75  $parameter = $arguments['parameter'];
76  $additionalParams = $arguments['additionalParams'];
77  $useCacheHash = $arguments['useCacheHash'];
78  $addQueryString = $arguments['addQueryString'];
79  $addQueryStringMethod = $arguments['addQueryStringMethod'];
80  $addQueryStringExclude = $arguments['addQueryStringExclude'];
81  $absolute = $arguments['absolute'];
82 
83  $content = '';
84  if ($parameter) {
85  $contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
86  $content = $contentObject->typoLink_URL(
87  [
88  'parameter' => self::createTypolinkParameterFromArguments($parameter, $additionalParams),
89  'useCacheHash' => $useCacheHash,
90  'addQueryString' => $addQueryString,
91  'addQueryString.' => [
92  'method' => $addQueryStringMethod,
93  'exclude' => $addQueryStringExclude
94  ],
95  'forceAbsoluteUrl' => $absolute
96  ]
97  );
98  }
99 
100  return $content;
101  }
102 
111  protected static function createTypolinkParameterFromArguments($parameter, $additionalParameters = '')
112  {
113  $typoLinkCodec = GeneralUtility::makeInstance(TypoLinkCodecService::class);
114  $typolinkConfiguration = $typoLinkCodec->decode($parameter);
115 
116  // Combine additionalParams
117  if ($additionalParameters) {
118  $typolinkConfiguration['additionalParams'] .= $additionalParameters;
119  }
120 
121  return $typoLinkCodec->encode($typolinkConfiguration);
122  }
123 }
static makeInstance($className,... $constructorArguments)