Created
November 6, 2013 17:35
-
-
Save maddy2101/7340636 to your computer and use it in GitHub Desktop.
TypoLink ViewHelper that accepts and extends the parameters for the typolink function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*************************************************************** | |
* Copyright notice | |
* | |
* (c) 2013 | |
* @author Anja Leichsenring <[email protected]> | |
* All rights reserved | |
* | |
* This script is part of the TYPO3 project. The TYPO3 project is | |
* free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation; either version 2 of the License, or | |
* (at your option) any later version. | |
* | |
* The GNU General Public License can be found at | |
* http://www.gnu.org/copyleft/gpl.html. | |
* | |
* This script is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* This copyright notice MUST APPEAR in all copies of the script! | |
***************************************************************/ | |
/** | |
* Generic ViewHelper to interpret content of TCEforms link wizard fields | |
* | |
* @category TYPO3 | |
* @package tv_lhag | |
* | |
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License | |
* | |
* == Example == | |
* {link} contains 19 _blank - "testtitle with whitespace" &X=y | |
* <code title="Full parameter usage"> | |
* <tv:typolink parameter="{link}" target="_blank" class="ico-class" title="some title"> | |
* </code> | |
* <output> | |
* <a href="index.php?id=19&X=y" title="some title" target="_blank" class="ico-class"> | |
* <span class="arrow"> | |
* something generic (testing inner link) | |
* </a> | |
* </output> | |
* | |
* | |
*/ | |
class Tx_TvLhag_ViewHelpers_TypolinkViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper { | |
/** | |
* @param string $parameter stdWrap.typolink style parameter string | |
* @param string $target | |
* @param string $class | |
* @param string $title | |
* @param string $additionalParams | |
* | |
* @return string | |
*/ | |
public function render($parameter, $target='', $class = '', $title='', $additionalParams='') { | |
// typolink from wizard might be linkparam target class title (divided by space) | |
$typolink = t3lib_div::unQuoteFilenames($parameter, TRUE); | |
// target gets overridden | |
if ($target) { | |
$typolink[1] = $target; | |
} else { | |
$typolink[1] = strlen($typolink[1]) > 0 ? $typolink[1] : '-'; | |
} | |
// class gets concatenated in case it is a real class (- is the negate value and will be removed) | |
if ($class) { | |
$typolink[2] = strlen($typolink[2]) > 1 ? '"' . $typolink[2] . ' ' . $class . '"' : '"' . $class . '"'; | |
} else { | |
$typolink[2] = strlen($typolink[2]) > 1 ? $typolink[2] : '-'; | |
} | |
// title gets overridden | |
if ($title) { | |
$typolink[3] = '"' . ($title) .'"'; | |
} | |
// additionalParams gets concatenated | |
if ($additionalParams) { | |
$typolink[4] = strlen($typolink[4]) > 0 ? $typolink[4] . $additionalParams : $additionalParams; | |
} | |
$parameter = implode(' ', $typolink); | |
$content = $this->renderChildren(); | |
if ($parameter) { | |
/** @var $contentObject tslib_cObj */ | |
$contentObject = t3lib_div::makeInstance('tslib_cObj'); | |
$contentObject->start(array(), ''); | |
$content = $contentObject->stdWrap($content, array( | |
'typolink.' => array( | |
'parameter' => $parameter | |
) | |
)); | |
} | |
return $content; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment