Skip to content

Instantly share code, notes, and snippets.

@JLNNN
Created March 16, 2017 09:26
Show Gist options
  • Save JLNNN/c9fcf267ad962269b44ac8fc7d375cf3 to your computer and use it in GitHub Desktop.
Save JLNNN/c9fcf267ad962269b44ac8fc7d375cf3 to your computer and use it in GitHub Desktop.
[TYPO3 6.2.x] Return typolink to tx_news entry or pageId set by DCE content
{namespace dce=ArminVieweg\Dce\ViewHelpers}
{namespace m=Tx_PmRendercontent_ViewHelpers}
<f:layout name="Default" />
<f:section name="main">
<a href="<m:Newslink uid="{field.link}" />">Link</a>
</f:section>
<?php
/**
* ViewHelper zur Rückgabe eines Links
*/
class Tx_PmRendercontent_ViewHelpers_NewslinkViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
/**
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
*/
protected $configurationManager;
/**
* @var Content Object
*/
protected $cObj;
/**
* Parse content element
*
* @param int UID des Links
* @param string Titel des Links
* @return string Link
*/
public function render($uid, $title = "") {
if (strpos($uid, "tx_news_domain_model_news") !== false) {
$uidInt = explode("_", $uid);
$uidInt = end($uidInt);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query('sys_category.single_pid', 'sys_category', 'sys_category_record_mm', 'tx_news_domain_model_news', 'AND tx_news_domain_model_news.uid = ' . intval($uidInt));
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$pageId = $row["single_pid"];
}
$linkConf = array(
'parameter' => $pageId,
'returnLast' => 'url',
'additionalParams' => "&tx_news_pi1[news]=" . intval($uidInt)
);
return $GLOBALS['TSFE']->cObj->typoLink($title, $linkConf);
} else {
$uidInt = explode("_", $uid);
$uidInt = end($uidInt);
$linkConf = array(
'parameter' => intval($uidInt),
'returnLast' => 'url'
);
return $GLOBALS['TSFE']->cObj->typoLink($title, $linkConf);
}
}
/**
* Injects Configuration Manager
*
* @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
* $configurationManager
* @return void
*/
public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager) {
$this->configurationManager = $configurationManager;
$this->cObj = $this->configurationManager->getContentObject();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment