TYPO3  7.6
Link/TypolinkViewHelper.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Link;
3 
4 /* *
5  * This script is part of the TYPO3 project - inspiring people to share! *
6  * *
7  * TYPO3 is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU General Public License version 2 as published by *
9  * the Free Software Foundation. *
10  * *
11  * This script is distributed in the hope that it will be useful, but *
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
14  * Public License for more details. *
15  * */
16 
23 
55 {
68  public function render($parameter, $target = '', $class = '', $title = '', $additionalParams = '', $additionalAttributes = array())
69  {
70  return static::renderStatic(
71  array(
72  'parameter' => $parameter,
73  'target' => $target,
74  'class' => $class,
75  'title' => $title,
76  'additionalParams' => $additionalParams,
77  'additionalAttributes' => $additionalAttributes
78  ),
80  $this->renderingContext
81  );
82  }
83 
93  {
94  $parameter = $arguments['parameter'];
95  $target = $arguments['target'];
96  $class = $arguments['class'];
97  $title = $arguments['title'];
98  $additionalParams = $arguments['additionalParams'];
99  $additionalAttributes = $arguments['additionalAttributes'];
100 
101  // Merge the $parameter with other arguments
102  $typolinkParameter = self::createTypolinkParameterArrayFromArguments($parameter, $target, $class, $title, $additionalParams);
103 
104  // array(param1 -> value1, param2 -> value2) --> "param1=value1 param2=>value2" for typolink.ATagParams
105  $extraAttributes = array();
106  foreach ($additionalAttributes as $attributeName => $attributeValue) {
107  $extraAttributes[] = $attributeName . '="' . htmlspecialchars($attributeValue) . '"';
108  }
109  $aTagParams = implode(' ', $extraAttributes);
110 
111  // If no link has to be rendered, the inner content will be returned as such
112  $content = $renderChildrenClosure();
113 
114  if ($parameter) {
116  $contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
117  $contentObject->start(array(), '');
118  $content = $contentObject->stdWrap(
119  $content,
120  array(
121  'typolink.' => array(
122  'parameter' => $typolinkParameter,
123  'ATagParams' => $aTagParams,
124  )
125  )
126  );
127  }
128 
129  return $content;
130  }
131 
143  protected static function createTypolinkParameterArrayFromArguments($parameter, $target = '', $class = '', $title = '', $additionalParams = '')
144  {
145  $typoLinkCodec = GeneralUtility::makeInstance(TypoLinkCodecService::class);
146  $typolinkConfiguration = $typoLinkCodec->decode($parameter);
147  if (empty($typolinkConfiguration)) {
148  return $typolinkConfiguration;
149  }
150 
151  // Override target if given in target argument
152  if ($target) {
153  $typolinkConfiguration['target'] = $target;
154  }
155 
156  // Combine classes if given in both "parameter" string and "class" argument
157  if ($class) {
158  if ($typolinkConfiguration['class']) {
159  $typolinkConfiguration['class'] .= ' ';
160  }
161  $typolinkConfiguration['class'] .= $class;
162  }
163 
164  // Override title if given in title argument
165  if ($title) {
166  $typolinkConfiguration['title'] = $title;
167  }
168 
169  // Combine additionalParams
170  if ($additionalParams) {
171  $typolinkConfiguration['additionalParams'] .= $additionalParams;
172  }
173 
174  return $typoLinkCodec->encode($typolinkConfiguration);
175  }
176 }