first commit
This commit is contained in:
commit
1218dd1517
12716 files changed
+989233
No files matched your search
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
|
||||
|
||||
/*
|
||||
* 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\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* A ViewHelper for creating URIs to extbase actions.
|
||||
*
|
||||
* Examples
|
||||
* ========
|
||||
*
|
||||
* URI to the show-action of the current controller::
|
||||
*
|
||||
* <f:uri.action action="show" />
|
||||
*
|
||||
* ``/page/path/name.html?tx_myextension_plugin[action]=show&tx_myextension_plugin[controller]=Standard&cHash=xyz``
|
||||
*
|
||||
* Depending on current page, routing and page path configuration.
|
||||
*/
|
||||
class ActionViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('action', 'string', 'Target action');
|
||||
$this->registerArgument('arguments', 'array', 'Arguments', false, []);
|
||||
$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', false, 0);
|
||||
$this->registerArgument('noCache', 'bool', 'Set this to disable caching for the target page. You should not need this.', false, false);
|
||||
$this->registerArgument('noCacheHash', 'bool', 'Set this to suppress the cHash query parameter created by TypoLink. You should not need this.', false, false);
|
||||
$this->registerArgument('section', 'string', 'The anchor to be added to the URI', false, '');
|
||||
$this->registerArgument('format', 'string', 'The requested format, e.g. ".html', false, '');
|
||||
$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.', false, false);
|
||||
$this->registerArgument('additionalParams', 'array', 'additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)', false, []);
|
||||
$this->registerArgument('absolute', 'bool', 'If set, an absolute URI is rendered', false, false);
|
||||
$this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URI', false, false);
|
||||
$this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'arguments to be removed from the URI. Only active if $addQueryString = TRUE', false, []);
|
||||
$this->registerArgument('addQueryStringMethod', 'string', 'Set which parameters will be kept. Only active if $addQueryString = TRUE');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
* @return string
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$pageUid = $arguments['pageUid'];
|
||||
$pageType = $arguments['pageType'];
|
||||
$noCache = $arguments['noCache'];
|
||||
$noCacheHash = $arguments['noCacheHash'];
|
||||
$section = $arguments['section'];
|
||||
$format = $arguments['format'];
|
||||
$linkAccessRestrictedPages = $arguments['linkAccessRestrictedPages'];
|
||||
$additionalParams = $arguments['additionalParams'];
|
||||
$absolute = $arguments['absolute'];
|
||||
$addQueryString = $arguments['addQueryString'];
|
||||
$argumentsToBeExcludedFromQueryString = $arguments['argumentsToBeExcludedFromQueryString'];
|
||||
$addQueryStringMethod = $arguments['addQueryStringMethod'];
|
||||
$action = $arguments['action'];
|
||||
$controller = $arguments['controller'];
|
||||
$extensionName = $arguments['extensionName'];
|
||||
$pluginName = $arguments['pluginName'];
|
||||
$arguments = $arguments['arguments'];
|
||||
|
||||
$uri = $renderingContext->getControllerContext()->getUriBuilder()
|
||||
->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, $arguments, $controller, $extensionName, $pluginName);
|
||||
return $uri;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
|
||||
|
||||
/*
|
||||
* 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\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Email URI ViewHelper.
|
||||
* Generates an email URI incorporating TYPO3s `spamProtectEmailAddresses`_ TypoScript setting.
|
||||
*
|
||||
* .. _spamProtectEmailAddresses: https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Setup/Config/Index.html#spamprotectemailaddresses
|
||||
*
|
||||
* Example
|
||||
* =======
|
||||
*
|
||||
* Basic email URI::
|
||||
*
|
||||
* <f:uri.email email="foo@bar.tld" />
|
||||
*
|
||||
* Output::
|
||||
*
|
||||
* javascript:linkTo_UnCryptMailto('ocknvq,hqqBdct0vnf');
|
||||
*
|
||||
* Depending on `spamProtectEmailAddresses`_ setting.
|
||||
*/
|
||||
class EmailViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('email', 'string', 'The email address to be turned into a URI', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string Rendered email link
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$email = $arguments['email'];
|
||||
|
||||
if (TYPO3_MODE === 'FE') {
|
||||
$emailParts = $GLOBALS['TSFE']->cObj->getMailTo($email, $email);
|
||||
return reset($emailParts);
|
||||
}
|
||||
return 'mailto:' . $email;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
|
||||
|
||||
/*
|
||||
* 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\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* A ViewHelper for creating URIs to external targets.
|
||||
* Currently the specified URI is simply passed through.
|
||||
*
|
||||
* Examples
|
||||
* ========
|
||||
*
|
||||
* Default
|
||||
* -------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:uri.external uri="http://www.typo3.org" />
|
||||
*
|
||||
* ``http://www.typo3.org``
|
||||
*
|
||||
* Custom default scheme
|
||||
* ---------------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:uri.external uri="typo3.org" defaultScheme="ftp" />
|
||||
*
|
||||
* ``ftp://typo3.org``
|
||||
*/
|
||||
class ExternalViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*
|
||||
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('uri', 'string', 'target URI', true);
|
||||
$this->registerArgument('defaultScheme', 'string', 'scheme the href attribute will be prefixed with if specified $uri does not contain a scheme already', false, 'http');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string Rendered URI
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$uri = $arguments['uri'];
|
||||
$defaultScheme = $arguments['defaultScheme'];
|
||||
|
||||
$scheme = parse_url($uri, PHP_URL_SCHEME);
|
||||
if ($scheme === null && $defaultScheme !== '') {
|
||||
$uri = $defaultScheme . '://' . $uri;
|
||||
}
|
||||
return $uri;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
|
||||
|
||||
/* *
|
||||
* This script is part of the TYPO3 project - inspiring people to share! *
|
||||
* *
|
||||
* TYPO3 is free software; you can redistribute it and/or modify it under *
|
||||
* the terms of the GNU General Public License version 2 as published by *
|
||||
* the Free Software Foundation. *
|
||||
* *
|
||||
* This script is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
|
||||
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
|
||||
* Public License for more details. *
|
||||
* */
|
||||
|
||||
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
|
||||
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Resizes a given image (if required) and returns its relative path.
|
||||
*
|
||||
* Examples
|
||||
* ========
|
||||
*
|
||||
* Default
|
||||
* -------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:uri.image src="EXT:myext/Resources/Public/typo3_logo.png" />
|
||||
*
|
||||
* Results in the following output within TYPO3 frontend:
|
||||
*
|
||||
* ``typo3conf/ext/myext/Resources/Public/typo3_logo.png``
|
||||
*
|
||||
* and the following output inside TYPO3 backend:
|
||||
*
|
||||
* ``../typo3conf/ext/myext/Resources/Public/typo3_logo.png``
|
||||
*
|
||||
* Image Object
|
||||
* ------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:uri.image image="{imageObject}" />
|
||||
*
|
||||
* Results in the following output within TYPO3 frontend:
|
||||
*
|
||||
* ``fileadmin/images/image.png``
|
||||
*
|
||||
* and the following output inside TYPO3 backend:
|
||||
*
|
||||
* ``fileadmin/images/image.png``
|
||||
*
|
||||
* Inline notation
|
||||
* ---------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* {f:uri.image(src: 'EXT:myext/Resources/Public/typo3_logo.png', minWidth: 30, maxWidth: 40)}
|
||||
*
|
||||
* ``typo3temp/assets/images/[b4c0e7ed5c].png``
|
||||
*
|
||||
* Depending on your TYPO3s encryption key.
|
||||
*
|
||||
* Non existing image
|
||||
* ------------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:uri.image src="NonExistingImage.png" />
|
||||
*
|
||||
* ``Could not get image resource for "NonExistingImage.png".``
|
||||
*/
|
||||
class ImageViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('src', 'string', 'src');
|
||||
$this->registerArgument('treatIdAsReference', 'bool', 'given src argument is a sys_file_reference record', false, false);
|
||||
$this->registerArgument('image', 'object', 'image');
|
||||
$this->registerArgument('crop', 'string|bool', 'overrule cropping of image (setting to FALSE disables the cropping set in FileReference)');
|
||||
$this->registerArgument('cropVariant', 'string', 'select a cropping variant, in case multiple croppings have been specified or stored in FileReference', false, 'default');
|
||||
|
||||
$this->registerArgument('width', 'string', 'width of the image. This can be a numeric value representing the fixed width of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.');
|
||||
$this->registerArgument('height', 'string', 'height of the image. This can be a numeric value representing the fixed height of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.');
|
||||
$this->registerArgument('minWidth', 'int', 'minimum width of the image');
|
||||
$this->registerArgument('minHeight', 'int', 'minimum height of the image');
|
||||
$this->registerArgument('maxWidth', 'int', 'maximum width of the image');
|
||||
$this->registerArgument('maxHeight', 'int', 'maximum height of the image');
|
||||
$this->registerArgument('absolute', 'bool', 'Force absolute URL', false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resizes the image (if required) and returns its path. If the image was not resized, the path will be equal to $src
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$src = $arguments['src'];
|
||||
$image = $arguments['image'];
|
||||
$treatIdAsReference = $arguments['treatIdAsReference'];
|
||||
$cropString = $arguments['crop'];
|
||||
$absolute = $arguments['absolute'];
|
||||
|
||||
if (($src === null && $image === null) || ($src !== null && $image !== null)) {
|
||||
throw new Exception('You must either specify a string src or a File object.', 1460976233);
|
||||
}
|
||||
|
||||
try {
|
||||
$imageService = self::getImageService();
|
||||
$image = $imageService->getImage($src, $image, $treatIdAsReference);
|
||||
|
||||
if ($cropString === null && $image->hasProperty('crop') && $image->getProperty('crop')) {
|
||||
$cropString = $image->getProperty('crop');
|
||||
}
|
||||
|
||||
$cropVariantCollection = CropVariantCollection::create((string)$cropString);
|
||||
$cropVariant = $arguments['cropVariant'] ?: 'default';
|
||||
$cropArea = $cropVariantCollection->getCropArea($cropVariant);
|
||||
$processingInstructions = [
|
||||
'width' => $arguments['width'],
|
||||
'height' => $arguments['height'],
|
||||
'minWidth' => $arguments['minWidth'],
|
||||
'minHeight' => $arguments['minHeight'],
|
||||
'maxWidth' => $arguments['maxWidth'],
|
||||
'maxHeight' => $arguments['maxHeight'],
|
||||
'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($image),
|
||||
];
|
||||
|
||||
$processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions);
|
||||
return $imageService->getImageUri($processedImage, $absolute);
|
||||
} catch (ResourceDoesNotExistException $e) {
|
||||
// thrown if file does not exist
|
||||
throw new Exception($e->getMessage(), 1509741907, $e);
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
// thrown if a file has been replaced with a folder
|
||||
throw new Exception($e->getMessage(), 1509741908, $e);
|
||||
} catch (\RuntimeException $e) {
|
||||
// RuntimeException thrown if a file is outside of a storage
|
||||
throw new Exception($e->getMessage(), 1509741909, $e);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
// thrown if file storage does not exist
|
||||
throw new Exception($e->getMessage(), 1509741910, $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of ImageService using object manager
|
||||
*
|
||||
* @return ImageService
|
||||
*/
|
||||
protected static function getImageService()
|
||||
{
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
|
||||
return $objectManager->get(ImageService::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
|
||||
|
||||
/*
|
||||
* 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\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* A ViewHelper for creating URIs to TYPO3 pages.
|
||||
*
|
||||
* Examples
|
||||
* ========
|
||||
*
|
||||
* URI to the current page
|
||||
* -----------------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:uri.page>page link</f:uri.page>
|
||||
*
|
||||
* ``/page/path/name.html``
|
||||
*
|
||||
* Depending on current page, routing and page path configuration.
|
||||
*
|
||||
* Query parameters
|
||||
* ----------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:uri.page pageUid="1" additionalParams="{foo: 'bar'}" />
|
||||
*
|
||||
* ``/page/path/name.html?foo=bar``
|
||||
*
|
||||
* Depending on current page, routing and page path configuration.
|
||||
*
|
||||
* Query parameters for extensions
|
||||
* -------------------------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:uri.page pageUid="1" additionalParams="{extension_key: {foo: 'bar'}}" />
|
||||
*
|
||||
* ``/page/path/name.html?extension_key[foo]=bar``
|
||||
*
|
||||
* Depending on current page, routing and page path configuration.
|
||||
*/
|
||||
class PageViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('pageUid', 'int', 'target PID');
|
||||
$this->registerArgument('additionalParams', 'array', 'query parameters to be attached to the resulting URI', false, []);
|
||||
$this->registerArgument('pageType', 'int', 'type of the target page. See typolink.parameter', false, 0);
|
||||
$this->registerArgument('noCache', 'bool', 'set this to disable caching for the target page. You should not need this.', false, false);
|
||||
$this->registerArgument('noCacheHash', 'bool', 'set this to suppress the cHash query parameter created by TypoLink. You should not need this.', false, false);
|
||||
$this->registerArgument('section', 'string', 'the anchor to be added to the URI', false, '');
|
||||
$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.', false, false);
|
||||
$this->registerArgument('absolute', 'bool', 'If set, the URI of the rendered link is absolute', false, false);
|
||||
$this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URI', false, false);
|
||||
$this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'arguments to be removed from the URI. Only active if $addQueryString = TRUE', false, []);
|
||||
$this->registerArgument('addQueryStringMethod', 'string', 'Set which parameters will be kept. Only active if $addQueryString = TRUE');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
* @return string Rendered page URI
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$pageUid = $arguments['pageUid'];
|
||||
$additionalParams = $arguments['additionalParams'];
|
||||
$pageType = $arguments['pageType'];
|
||||
$noCache = $arguments['noCache'];
|
||||
$noCacheHash = $arguments['noCacheHash'];
|
||||
$section = $arguments['section'];
|
||||
$linkAccessRestrictedPages = $arguments['linkAccessRestrictedPages'];
|
||||
$absolute = $arguments['absolute'];
|
||||
$addQueryString = $arguments['addQueryString'];
|
||||
$argumentsToBeExcludedFromQueryString = $arguments['argumentsToBeExcludedFromQueryString'];
|
||||
$addQueryStringMethod = $arguments['addQueryStringMethod'];
|
||||
|
||||
$uriBuilder = $renderingContext->getControllerContext()->getUriBuilder();
|
||||
$uri = $uriBuilder->setTargetPageUid($pageUid)->setTargetPageType($pageType)->setNoCache($noCache)->setUseCacheHash(!$noCacheHash)->setSection($section)->setLinkAccessRestrictedPages($linkAccessRestrictedPages)->setArguments($additionalParams)->setCreateAbsoluteUri($absolute)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->setAddQueryStringMethod($addQueryStringMethod)->build();
|
||||
return $uri;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
|
||||
|
||||
/*
|
||||
* 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\Core\Utility\PathUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* A ViewHelper for creating URIs to resources.
|
||||
*
|
||||
* Examples
|
||||
* ========
|
||||
*
|
||||
* Defaults
|
||||
* --------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <link href="{f:uri.resource(path:'css/stylesheet.css')}" rel="stylesheet" />
|
||||
*
|
||||
* Output::
|
||||
*
|
||||
* <link href="typo3conf/ext/example_extension/Resources/Resources/Public/css/stylesheet.css" rel="stylesheet" />
|
||||
*
|
||||
* Depending on current extension.
|
||||
*
|
||||
* With extension name
|
||||
* -------------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <link href="{f:uri.resource(path:'css/stylesheet.css', extensionName: 'AnotherExtension')}" rel="stylesheet" />
|
||||
*
|
||||
* Output::
|
||||
*
|
||||
* <link href="typo3conf/ext/another_extension/Resources/Resources/Public/css/stylesheet.css" rel="stylesheet" />
|
||||
*/
|
||||
class ResourceViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('path', 'string', 'The path and filename of the resource (relative to Public resource directory of the extension).', true);
|
||||
$this->registerArgument('extensionName', 'string', 'Target extension name. If not set, the current extension name will be used');
|
||||
$this->registerArgument('absolute', 'bool', 'If set, an absolute URI is rendered', false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the URI to the resource. The filename is used from child content.
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
* @return string The URI to the resource
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$path = $arguments['path'];
|
||||
$extensionName = $arguments['extensionName'];
|
||||
$absolute = $arguments['absolute'];
|
||||
|
||||
if ($extensionName === null) {
|
||||
$extensionName = $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName();
|
||||
}
|
||||
$uri = 'EXT:' . GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/Resources/Public/' . $path;
|
||||
$uri = GeneralUtility::getFileAbsFileName($uri);
|
||||
if ($absolute === false && $uri !== false) {
|
||||
$uri = PathUtility::getAbsoluteWebPath($uri);
|
||||
}
|
||||
if ($absolute === true) {
|
||||
$uri = PathUtility::stripPathSitePrefix($uri);
|
||||
$uri = $renderingContext->getControllerContext()->getRequest()->getBaseUri() . $uri;
|
||||
}
|
||||
return $uri;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Fluid\ViewHelpers\Uri;
|
||||
|
||||
/*
|
||||
* 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\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* A ViewHelper to create uris from fields supported by the link wizard.
|
||||
*
|
||||
* Example
|
||||
* =======
|
||||
*
|
||||
* ``{link}`` contains ``19 - - - &X=y``
|
||||
*
|
||||
* Please note that due to the nature of typolink you have to provide a full
|
||||
* set of parameters.
|
||||
* If you use the parameter only, then target, class and title will be discarded.
|
||||
*
|
||||
* Minimal usage
|
||||
* -------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:uri.typolink parameter="{link}" />
|
||||
*
|
||||
* ``/page/path/name.html?X=y``
|
||||
*
|
||||
* Depending on routing and page path configuration.
|
||||
*
|
||||
* Full parameter usage
|
||||
* --------------------
|
||||
*
|
||||
* ::
|
||||
*
|
||||
* <f:uri.typolink parameter="{link}" additionalParams="&u=b" useCacheHash="true" />
|
||||
*
|
||||
* ``/page/path/name.html?X=y&u=b``
|
||||
*
|
||||
* Depending on routing and page path configuration.
|
||||
*/
|
||||
class TypolinkViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Initialize arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('parameter', 'string', 'stdWrap.typolink style parameter string', true);
|
||||
$this->registerArgument('additionalParams', 'string', 'stdWrap.typolink additionalParams', 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$parameter = $arguments['parameter'];
|
||||
$additionalParams = $arguments['additionalParams'];
|
||||
$useCacheHash = $arguments['useCacheHash'];
|
||||
$addQueryString = $arguments['addQueryString'];
|
||||
$addQueryStringMethod = $arguments['addQueryStringMethod'];
|
||||
$addQueryStringExclude = $arguments['addQueryStringExclude'];
|
||||
$absolute = $arguments['absolute'];
|
||||
|
||||
$content = '';
|
||||
if ($parameter) {
|
||||
$contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
|
||||
$content = $contentObject->typoLink_URL(
|
||||
[
|
||||
'parameter' => self::createTypolinkParameterFromArguments($parameter, $additionalParams),
|
||||
'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 $additionalParameters
|
||||
*
|
||||
* @return string The final TypoLink string
|
||||
*/
|
||||
protected static function createTypolinkParameterFromArguments($parameter, $additionalParameters = '')
|
||||
{
|
||||
$typoLinkCodec = GeneralUtility::makeInstance(TypoLinkCodecService::class);
|
||||
$typolinkConfiguration = $typoLinkCodec->decode($parameter);
|
||||
|
||||
// Combine additionalParams
|
||||
if ($additionalParameters) {
|
||||
$typolinkConfiguration['additionalParams'] .= $additionalParameters;
|
||||
}
|
||||
|
||||
return $typoLinkCodec->encode($typolinkConfiguration);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user