first commit
This commit is contained in:
commit
1218dd1517
12716 files changed
+989233
No files matched your search
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Fluid\ViewHelpers\Link;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
|
||||
|
||||
/**
|
||||
* A ViewHelper for creating links to extbase actions.
|
||||
*
|
||||
* Examples
|
||||
* ========
|
||||
*
|
||||
* link to the show-action of the current controller::
|
||||
*
|
||||
* <f:link.action action="show">action link</f:link.action>
|
||||
*
|
||||
* Output::
|
||||
*
|
||||
* <a href="index.php?id=123&tx_myextension_plugin[action]=show&tx_myextension_plugin[controller]=Standard&cHash=xyz">action link</a>
|
||||
*
|
||||
* Depending on the current page and your TypoScript configuration.
|
||||
*/
|
||||
class ActionViewHelper extends AbstractTagBasedViewHelper
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tagName = 'a';
|
||||
|
||||
/**
|
||||
* Arguments initialization
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
parent::initializeArguments();
|
||||
$this->registerUniversalTagAttributes();
|
||||
$this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
|
||||
$this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
|
||||
$this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
|
||||
$this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
|
||||
$this->registerArgument('action', 'string', 'Target action');
|
||||
$this->registerArgument('controller', 'string', 'Target controller. If NULL current controllerName is used');
|
||||
$this->registerArgument('extensionName', 'string', 'Target Extension Name (without "tx_" prefix and no underscores). If NULL the current extension name is used');
|
||||
$this->registerArgument('pluginName', 'string', 'Target plugin. If empty, the current plugin name is used');
|
||||
$this->registerArgument('pageUid', 'int', 'Target page. See TypoLink destination');
|
||||
$this->registerArgument('pageType', 'int', 'Type of the target page. See typolink.parameter');
|
||||
$this->registerArgument('noCache', 'bool', 'Set this to disable caching for the target page. You should not need this.');
|
||||
$this->registerArgument('noCacheHash', 'bool', 'Set this to suppress the cHash query parameter created by TypoLink. You should not need this.');
|
||||
$this->registerArgument('section', 'string', 'The anchor to be added to the URI');
|
||||
$this->registerArgument('format', 'string', 'The requested format, e.g. ".html');
|
||||
$this->registerArgument('linkAccessRestrictedPages', 'bool', 'If set, links pointing to access restricted pages will still link to the page even though the page cannot be accessed.');
|
||||
$this->registerArgument('additionalParams', 'array', 'Additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)');
|
||||
$this->registerArgument('absolute', 'bool', 'If set, the URI of the rendered link is absolute');
|
||||
$this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URI');
|
||||
$this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'Arguments to be removed from the URI. Only active if $addQueryString = TRUE');
|
||||
$this->registerArgument('addQueryStringMethod', 'string', 'Set which parameters will be kept. Only active if $addQueryString = TRUE');
|
||||
$this->registerArgument('arguments', 'array', 'Arguments for the controller action, associative array');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Rendered link
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
$action = $this->arguments['action'];
|
||||
$controller = $this->arguments['controller'];
|
||||
$extensionName = $this->arguments['extensionName'];
|
||||
$pluginName = $this->arguments['pluginName'];
|
||||
$pageUid = (int)$this->arguments['pageUid'] ?: null;
|
||||
$pageType = (int)$this->arguments['pageType'];
|
||||
$noCache = (bool)$this->arguments['noCache'];
|
||||
$noCacheHash = (bool)$this->arguments['noCacheHash'];
|
||||
$section = (string)$this->arguments['section'];
|
||||
$format = (string)$this->arguments['format'];
|
||||
$linkAccessRestrictedPages = (bool)$this->arguments['linkAccessRestrictedPages'];
|
||||
$additionalParams = (array)$this->arguments['additionalParams'];
|
||||
$absolute = (bool)$this->arguments['absolute'];
|
||||
$addQueryString = (bool)$this->arguments['addQueryString'];
|
||||
$argumentsToBeExcludedFromQueryString = (array)$this->arguments['argumentsToBeExcludedFromQueryString'];
|
||||
$addQueryStringMethod = $this->arguments['addQueryStringMethod'];
|
||||
$parameters = $this->arguments['arguments'];
|
||||
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
|
||||
$uri = $uriBuilder
|
||||
->reset()
|
||||
->setTargetPageUid($pageUid)
|
||||
->setTargetPageType($pageType)
|
||||
->setNoCache($noCache)
|
||||
->setUseCacheHash(!$noCacheHash)
|
||||
->setSection($section)
|
||||
->setFormat($format)
|
||||
->setLinkAccessRestrictedPages($linkAccessRestrictedPages)
|
||||
->setArguments($additionalParams)
|
||||
->setCreateAbsoluteUri($absolute)
|
||||
->setAddQueryString($addQueryString)
|
||||
->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)
|
||||
->setAddQueryStringMethod($addQueryStringMethod)
|
||||
->uriFor($action, $parameters, $controller, $extensionName, $pluginName);
|
||||
if ($uri === '') {
|
||||
return $this->renderChildren();
|
||||
}
|
||||
$this->tag->addAttribute('href', $uri);
|
||||
$this->tag->setContent($this->renderChildren());
|
||||
$this->tag->forceClosingTag(true);
|
||||
return $this->tag->render();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Fluid\ViewHelpers\Link;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
|
||||
|
||||
/**
|
||||
* Email link ViewHelper.
|
||||
* Generates an email link incorporating TYPO3s `spamProtectEmailAddresses`_ TypoScript setting.
|
||||
*
|
||||
* .. _spamProtectEmailAddresses: https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Setup/Config/Index.html#spamprotectemailaddresses
|
||||
*
|
||||
* Examples
|
||||
* ========
|
||||
*
|
||||
* Basic email link
|
||||
* ----------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:link.email email="foo@bar.tld" />
|
||||
*
|
||||
* Output::
|
||||
*
|
||||
* <a href="javascript:linkTo_UnCryptMailto('ocknvq,hqqBdct0vnf');">foo(at)bar.tld</a>
|
||||
*
|
||||
* Depending on `spamProtectEmailAddresses`_ setting.
|
||||
*
|
||||
* Email link with custom linktext
|
||||
* -------------------------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:link.email email="foo@bar.tld">some custom content</f:link.email>
|
||||
*
|
||||
* Output::
|
||||
*
|
||||
* <a href="javascript:linkTo_UnCryptMailto('ocknvq,hqqBdct0vnf');">some custom content</a>
|
||||
*
|
||||
* Depending on `spamProtectEmailAddresses`_ setting.
|
||||
*/
|
||||
class EmailViewHelper extends AbstractTagBasedViewHelper
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tagName = 'a';
|
||||
|
||||
/**
|
||||
* Arguments initialization
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('email', 'string', 'The email address to be turned into a link', true);
|
||||
$this->registerUniversalTagAttributes();
|
||||
$this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
|
||||
$this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
|
||||
$this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
|
||||
$this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Rendered email link
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
$email = $this->arguments['email'];
|
||||
|
||||
if ($this->isFrontendAvailable()) {
|
||||
list($linkHref, $linkText) = $GLOBALS['TSFE']->cObj->getMailTo($email, '');
|
||||
$escapeSpecialCharacters = !isset($GLOBALS['TSFE']->spamProtectEmailAddresses) || $GLOBALS['TSFE']->spamProtectEmailAddresses !== 'ascii';
|
||||
} else {
|
||||
$linkHref = 'mailto:' . $email;
|
||||
$linkText = htmlspecialchars($email);
|
||||
$escapeSpecialCharacters = true;
|
||||
}
|
||||
$tagContent = $this->renderChildren();
|
||||
if ($tagContent !== null) {
|
||||
$linkText = $tagContent;
|
||||
}
|
||||
$this->tag->setContent($linkText);
|
||||
$this->tag->addAttribute('href', $linkHref, $escapeSpecialCharacters);
|
||||
$this->tag->forceClosingTag(true);
|
||||
return $this->tag->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function isFrontendAvailable()
|
||||
{
|
||||
return TYPO3_MODE === 'FE';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Fluid\ViewHelpers\Link;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
|
||||
|
||||
/**
|
||||
* A ViewHelper for creating links to external targets.
|
||||
*
|
||||
* Examples
|
||||
* ========
|
||||
*
|
||||
* Default
|
||||
* -------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:link.external uri="http://www.typo3.org" target="_blank">external link</f:link.external>
|
||||
*
|
||||
* Output::
|
||||
*
|
||||
* <a href="http://www.typo3.org" target="_blank">external link</a>
|
||||
*
|
||||
* Custom default scheme
|
||||
* ---------------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:link.external uri="typo3.org" defaultScheme="ftp">external ftp link</f:link.external>
|
||||
*
|
||||
* Output::
|
||||
*
|
||||
* <a href="ftp://typo3.org">external ftp link</a>
|
||||
*/
|
||||
class ExternalViewHelper extends AbstractTagBasedViewHelper
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tagName = 'a';
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('uri', 'string', 'The URI that will be put in the href attribute of the rendered link tag', true);
|
||||
$this->registerArgument('defaultScheme', 'string', 'Scheme the href attribute will be prefixed with if specified $uri does not contain a scheme already', false, 'http');
|
||||
$this->registerUniversalTagAttributes();
|
||||
$this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
|
||||
$this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
|
||||
$this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
|
||||
$this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Rendered link
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
$uri = $this->arguments['uri'];
|
||||
$defaultScheme = $this->arguments['defaultScheme'];
|
||||
|
||||
$scheme = parse_url($uri, PHP_URL_SCHEME);
|
||||
if ($scheme === null && $defaultScheme !== '') {
|
||||
$uri = $defaultScheme . '://' . $uri;
|
||||
}
|
||||
$this->tag->addAttribute('href', $uri);
|
||||
$this->tag->setContent($this->renderChildren());
|
||||
$this->tag->forceClosingTag(true);
|
||||
|
||||
return $this->tag->render();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Fluid\ViewHelpers\Link;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
|
||||
|
||||
/**
|
||||
* A ViewHelper for creating links to TYPO3 pages.
|
||||
*
|
||||
* Examples
|
||||
* ========
|
||||
*
|
||||
* Link to the current page
|
||||
* ------------------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:link.page>page link</f:link.page>
|
||||
*
|
||||
* Output::
|
||||
*
|
||||
* <a href="/page/path/name.html">page link</a>
|
||||
*
|
||||
* Depending on current page, routing and page path configuration.
|
||||
*
|
||||
* Query parameters
|
||||
* ----------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:link.page pageUid="1" additionalParams="{foo: 'bar'}">page link</f:link.page>
|
||||
*
|
||||
* Output::
|
||||
*
|
||||
* <a href="/page/path/name.html?foo=bar">page link</a>
|
||||
*
|
||||
* Depending on current page, routing and page path configuration.
|
||||
*
|
||||
* Query parameters for extensions
|
||||
* -------------------------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:link.page pageUid="1" additionalParams="{extension_key: {foo: 'bar'}}">page link</f:link.page>
|
||||
*
|
||||
* Output::
|
||||
*
|
||||
* <a href="/page/path/name.html?extension_key[foo]=bar">page link</a>
|
||||
*
|
||||
* Depending on current page, routing and page path configuration.
|
||||
*/
|
||||
class PageViewHelper extends AbstractTagBasedViewHelper
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tagName = 'a';
|
||||
|
||||
/**
|
||||
* Arguments initialization
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
parent::initializeArguments();
|
||||
$this->registerUniversalTagAttributes();
|
||||
$this->registerTagAttribute('target', 'string', 'Target of link', false);
|
||||
$this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document', false);
|
||||
$this->registerArgument('pageUid', 'int', 'Target page. See TypoLink destination');
|
||||
$this->registerArgument('pageType', 'int', 'Type of the target page. See typolink.parameter');
|
||||
$this->registerArgument('noCache', 'bool', 'Set this to disable caching for the target page. You should not need this.');
|
||||
$this->registerArgument('noCacheHash', 'bool', 'Set this to suppress the cHash query parameter created by TypoLink. You should not need this.');
|
||||
$this->registerArgument('section', 'string', 'The anchor to be added to the URI');
|
||||
$this->registerArgument('linkAccessRestrictedPages', 'bool', 'If set, links pointing to access restricted pages will still link to the page even though the page cannot be accessed.');
|
||||
$this->registerArgument('additionalParams', 'array', 'Additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)');
|
||||
$this->registerArgument('absolute', 'bool', 'If set, the URI of the rendered link is absolute');
|
||||
$this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URI');
|
||||
$this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'Arguments to be removed from the URI. Only active if $addQueryString = TRUE');
|
||||
$this->registerArgument('addQueryStringMethod', 'string', 'Set which parameters will be kept. Only active if $addQueryString = TRUE');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Rendered page URI
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
$pageUid = isset($this->arguments['pageUid']) ? (int)$this->arguments['pageUid'] : null;
|
||||
$pageType = isset($this->arguments['pageType']) ? (int)$this->arguments['pageType'] : 0;
|
||||
$noCache = isset($this->arguments['noCache']) ? (bool)$this->arguments['noCache'] : false;
|
||||
$noCacheHash = isset($this->arguments['noCacheHash']) ? (bool)$this->arguments['noCacheHash'] : false;
|
||||
$section = isset($this->arguments['section']) ? (string)$this->arguments['section'] : '';
|
||||
$linkAccessRestrictedPages = isset($this->arguments['linkAccessRestrictedPages']) ? (bool)$this->arguments['linkAccessRestrictedPages'] : false;
|
||||
$additionalParams = isset($this->arguments['additionalParams']) ? (array)$this->arguments['additionalParams'] : [];
|
||||
$absolute = isset($this->arguments['absolute']) ? (bool)$this->arguments['absolute'] : false;
|
||||
$addQueryString = isset($this->arguments['addQueryString']) ? (bool)$this->arguments['addQueryString'] : false;
|
||||
$argumentsToBeExcludedFromQueryString = isset($this->arguments['argumentsToBeExcludedFromQueryString']) ? (array)$this->arguments['argumentsToBeExcludedFromQueryString'] : [];
|
||||
$addQueryStringMethod = $this->arguments['addQueryStringMethod'] ?? null;
|
||||
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
|
||||
$uri = $uriBuilder->reset()
|
||||
->setTargetPageUid($pageUid)
|
||||
->setTargetPageType($pageType)
|
||||
->setNoCache($noCache)
|
||||
->setUseCacheHash(!$noCacheHash)
|
||||
->setSection($section)
|
||||
->setLinkAccessRestrictedPages($linkAccessRestrictedPages)
|
||||
->setArguments($additionalParams)
|
||||
->setCreateAbsoluteUri($absolute)
|
||||
->setAddQueryString($addQueryString)
|
||||
->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)
|
||||
->setAddQueryStringMethod($addQueryStringMethod)
|
||||
->build();
|
||||
if ((string)$uri !== '') {
|
||||
$this->tag->addAttribute('href', $uri);
|
||||
$this->tag->setContent($this->renderChildren());
|
||||
$this->tag->forceClosingTag(true);
|
||||
$result = $this->tag->render();
|
||||
} else {
|
||||
$result = $this->renderChildren();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Fluid\ViewHelpers\Link;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||
use TYPO3\CMS\Frontend\Service\TypoLinkCodecService;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* A ViewHelper to create links from fields supported by the link wizard
|
||||
*
|
||||
* Example
|
||||
* =======
|
||||
*
|
||||
* ``{link}`` contains: ``t3://page?uid=2&arg1=val1#9 _blank some-css-class "Title containing Whitespace"``.
|
||||
*
|
||||
* Or a legacy version from older TYPO3 versions:
|
||||
* ``{link}`` contains: ``9 _blank - "testtitle with whitespace" &X=y``.
|
||||
*
|
||||
* Minimal usage
|
||||
* -------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:link.typolink parameter="{link}">
|
||||
* Linktext
|
||||
* </f:link.typolink>
|
||||
*
|
||||
* Output::
|
||||
*
|
||||
* <a href="/page/path/name.html?X=y" title="testtitle with whitespace" target="_blank">
|
||||
* Linktext
|
||||
* </a>
|
||||
*
|
||||
* Depending on current page, routing and page path configuration.
|
||||
*
|
||||
* Full parameter usage
|
||||
* --------------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:link.typolink parameter="{link}" additionalParams="&u=b"
|
||||
* target="_blank"
|
||||
* class="ico-class" title="some title"
|
||||
* additionalAttributes="{type:'button'}"
|
||||
* useCacheHash="true"
|
||||
* >
|
||||
* Linktext
|
||||
* </f:link.typolink>
|
||||
*
|
||||
* Output::
|
||||
*
|
||||
* <a href="/page/path/name.html?X=y&u=b" title="some title" target="_blank" class="ico-class" type="button">
|
||||
* Linktext
|
||||
* </a>
|
||||
*
|
||||
* Depending on routing and page path configuration.
|
||||
*/
|
||||
class TypolinkViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $escapeOutput = false;
|
||||
|
||||
/**
|
||||
* Initialize ViewHelper arguments
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('parameter', 'string', 'stdWrap.typolink style parameter string', true);
|
||||
$this->registerArgument('target', 'string', '', false, '');
|
||||
$this->registerArgument('class', 'string', '', false, '');
|
||||
$this->registerArgument('title', 'string', '', false, '');
|
||||
$this->registerArgument('additionalParams', 'string', '', false, '');
|
||||
$this->registerArgument('additionalAttributes', 'array', '', false, []);
|
||||
$this->registerArgument('useCacheHash', 'bool', '', false, false);
|
||||
$this->registerArgument('addQueryString', 'bool', '', false, false);
|
||||
$this->registerArgument('addQueryStringMethod', 'string', '', false, 'GET');
|
||||
$this->registerArgument('addQueryStringExclude', 'string', '', false, '');
|
||||
$this->registerArgument('absolute', 'bool', 'Ensure the resulting URL is an absolute URL', false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
* @return mixed|string
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \UnexpectedValueException
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$parameter = $arguments['parameter'] ?? '';
|
||||
$target = $arguments['target'] ?? '';
|
||||
$class = $arguments['class'] ?? '';
|
||||
$title = $arguments['title'] ?? '';
|
||||
$additionalParams = $arguments['additionalParams'] ?? '';
|
||||
$additionalAttributes = $arguments['additionalAttributes'] ?? [];
|
||||
$useCacheHash = $arguments['useCacheHash'] ?? false;
|
||||
$addQueryString = $arguments['addQueryString'] ?? false;
|
||||
$addQueryStringMethod = $arguments['addQueryStringMethod'] ?? 'GET';
|
||||
$addQueryStringExclude = $arguments['addQueryStringExclude'] ?? '';
|
||||
$absolute = $arguments['absolute'] ?? false;
|
||||
|
||||
// Merge the $parameter with other arguments
|
||||
$typolinkParameter = self::createTypolinkParameterArrayFromArguments($parameter, $target, $class, $title, $additionalParams);
|
||||
|
||||
// array(param1 -> value1, param2 -> value2) --> param1="value1" param2="value2" for typolink.ATagParams
|
||||
$extraAttributes = [];
|
||||
foreach ($additionalAttributes as $attributeName => $attributeValue) {
|
||||
$extraAttributes[] = $attributeName . '="' . htmlspecialchars($attributeValue) . '"';
|
||||
}
|
||||
$aTagParams = implode(' ', $extraAttributes);
|
||||
|
||||
// If no link has to be rendered, the inner content will be returned as such
|
||||
$content = (string)$renderChildrenClosure();
|
||||
|
||||
if ($parameter) {
|
||||
/** @var ContentObjectRenderer $contentObject */
|
||||
$contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
|
||||
$contentObject->start([], '');
|
||||
$content = $contentObject->stdWrap(
|
||||
$content,
|
||||
[
|
||||
'typolink.' => [
|
||||
'parameter' => $typolinkParameter,
|
||||
'ATagParams' => $aTagParams,
|
||||
'useCacheHash' => $useCacheHash,
|
||||
'addQueryString' => $addQueryString,
|
||||
'addQueryString.' => [
|
||||
'method' => $addQueryStringMethod,
|
||||
'exclude' => $addQueryStringExclude
|
||||
],
|
||||
'forceAbsoluteUrl' => $absolute
|
||||
]
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms ViewHelper arguments to typo3link.parameters.typoscript option as array.
|
||||
*
|
||||
* @param string $parameter Example: 19 _blank - "testtitle \"with whitespace\"" &X=y
|
||||
* @param string $target
|
||||
* @param string $class
|
||||
* @param string $title
|
||||
* @param string $additionalParams
|
||||
*
|
||||
* @return string The final TypoLink string
|
||||
*/
|
||||
protected static function createTypolinkParameterArrayFromArguments($parameter, $target = '', $class = '', $title = '', $additionalParams = '')
|
||||
{
|
||||
$typoLinkCodec = GeneralUtility::makeInstance(TypoLinkCodecService::class);
|
||||
$typolinkConfiguration = $typoLinkCodec->decode($parameter);
|
||||
if (empty($typolinkConfiguration)) {
|
||||
return $typolinkConfiguration;
|
||||
}
|
||||
|
||||
// Override target if given in target argument
|
||||
if ($target) {
|
||||
$typolinkConfiguration['target'] = $target;
|
||||
}
|
||||
|
||||
// Combine classes if given in both "parameter" string and "class" argument
|
||||
if ($class) {
|
||||
$classes = explode(' ', trim($typolinkConfiguration['class']) . ' ' . trim($class));
|
||||
$typolinkConfiguration['class'] = implode(' ', array_unique(array_filter($classes)));
|
||||
}
|
||||
|
||||
// Override title if given in title argument
|
||||
if ($title) {
|
||||
$typolinkConfiguration['title'] = $title;
|
||||
}
|
||||
|
||||
// Combine additionalParams
|
||||
if ($additionalParams) {
|
||||
$typolinkConfiguration['additionalParams'] .= $additionalParams;
|
||||
}
|
||||
|
||||
return $typoLinkCodec->encode($typolinkConfiguration);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user