Created
March 16, 2017 09:26
-
-
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
This file contains 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
<config> | |
<type>group</type> | |
<internal_type>db</internal_type> | |
<allowed>pages,tx_news_domain_model_news</allowed> | |
<size>1</size> | |
<minitems>1</minitems> | |
<maxitems>1</maxitems> | |
<show_thumbs>0</show_thumbs> | |
</config> |
This file contains 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
{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> |
This file contains 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 | |
/** | |
* 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