Files
oai-symfony/typo3conf/ext/news/Classes/ViewHelpers/TargetLinkViewHelper.php
2026-07-03 17:53:31 +02:00

64 lines
1.8 KiB
PHP

<?php
namespace GeorgRinger\News\ViewHelpers;
/**
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInterface;
/**
* ViewHelper to get the target out of the typolink
*
* # Example: Basic Example
* # Description: {relatedLink.uri} is defined as "123 _blank"
* <code>
* <f:link.typolink parameter="{relatedLink.uri}" target="{n:targetLink(link:relatedLink.uri)}">Link</f:link.typolink>
* </code>
* <output>
* A link to the page with uid 123 and target set to "_blank"
* </output>
*/
class TargetLinkViewHelper extends AbstractViewHelper implements ViewHelperInterface
{
use CompileWithRenderStatic;
/**
* Initialize arguments.
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('link', 'string', 'Link', true);
}
/**
* Returns the correct target of a typolink
*
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return mixed
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
$params = explode(' ', $arguments['link']);
// The target is on the 2nd place and must start with a '_'
if (count($params) >= 2 && substr($params[1], 0, 1) === '_') {
return $params[1];
}
return '';
}
}