Skip to content

Instantly share code, notes, and snippets.

@xperseguers
Last active November 15, 2016 16:27
Show Gist options
  • Save xperseguers/fe448a7d20aa67b2aa466d5f2faf131c to your computer and use it in GitHub Desktop.
Save xperseguers/fe448a7d20aa67b2aa466d5f2faf131c to your computer and use it in GitHub Desktop.
Uri/ActionViewHelper without invoking RealURL
<?php
/*
* 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 TYPO3 source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace Causal\LbTemplate\ViewHelpers\Uri;
/**
* A view helper for creating URIs to extbase actions without invoking RealURL (if enabled).
*
* = Examples =
*
* <code title="URI to the show-action of the current controller">
* <t:uri.action action="show" />
* </code>
* <output>
* index.php?id=123&tx_myextension_plugin[action]=show&tx_myextension_plugin[controller]=Standard&cHash=xyz
* (depending on the current page and your TS configuration)
* </output>
*/
class ActionViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Uri\ActionViewHelper
{
/**
* @param string $action Target action
* @param array $arguments Arguments
* @param string $controller Target controller. If NULL current controllerName is used
* @param string $extensionName Target Extension Name (without "tx_" prefix and no underscores). If NULL the current extension name is used
* @param string $pluginName Target plugin. If empty, the current plugin name is used
* @param int $pageUid target page. See TypoLink destination
* @param int $pageType type of the target page. See typolink.parameter
* @param bool $noCache set this to disable caching for the target page. You should not need this.
* @param bool $noCacheHash set this to suppress the cHash query parameter created by TypoLink. You should not need this.
* @param string $section the anchor to be added to the URI
* @param string $format The requested format, e.g. ".html
* @param bool $linkAccessRestrictedPages If set, links pointing to access restricted pages will still link to the page even though the page cannot be accessed.
* @param array $additionalParams additional query parameters that won't be prefixed like $arguments (overrule $arguments)
* @param bool $absolute If set, the URI of the rendered link is absolute
* @param bool $addQueryString If set, the current query parameters will be kept in the URI
* @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE
* @param string $addQueryStringMethod Set which parameters will be kept. Only active if $addQueryString = TRUE
* @return string Rendered link
*/
public function render($action = null, array $arguments = [], $controller = null, $extensionName = null, $pluginName = null, $pageUid = null, $pageType = 0, $noCache = false, $noCacheHash = false, $section = '', $format = '', $linkAccessRestrictedPages = false, array $additionalParams = [], $absolute = false, $addQueryString = false, array $argumentsToBeExcludedFromQueryString = [], $addQueryStringMethod = null)
{
$backupTypolink = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typoLink_PostProc'];
$backupLinkData = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'];
if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typoLink_PostProc']['realurl'])) {
unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typoLink_PostProc']['realurl']);
}
if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc']['realurl'])) {
unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc']['realurl']);
}
$link = parent::render($action, $arguments, $controller, $extensionName, $pluginName, $pageUid, $pageType, $noCache, $noCacheHash, $section, $format, $linkAccessRestrictedPages, $additionalParams, $absolute, $addQueryString, $argumentsToBeExcludedFromQueryString, $addQueryStringMethod);
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typoLink_PostProc'] = $backupTypolink;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'] = $backupLinkData;
return $link;
}
}
@marble
Copy link

marble commented Nov 15, 2016

Fine! Maybe I got it wrong or mix things up here but I thought you had tweeted about some JS solution as well.

Switching on my mental mode "What does this mean for documentation?": that raises questions (Actually I haven't created any Gists myself, I think):

  • How can documentation help to provide and share viewhelpers?
  • Will Gists stay forever? I mean, as long as Github exists and the owner doesn't delete them.
  • I you have new insights, you'll update the Gist probably?
  • Can Gists help in creating a Viewhelper library? Or a snippet collection?

Thinking ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment