Skip to content

Instantly share code, notes, and snippets.

@JLNNN
Last active March 16, 2017 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JLNNN/32d6222baf2507a3b1e9ff9db82fbbe7 to your computer and use it in GitHub Desktop.
Save JLNNN/32d6222baf2507a3b1e9ff9db82fbbe7 to your computer and use it in GitHub Desktop.
[TYPO3 6.2.x] Hook for LinkHandler extension for different tx_news detail pages separated by sys_category single view pid (no namespaces, using extension https://github.com/AOEpeople/linkhandler)
<?php
class ext_linkhandler extends Aoe\Linkhandler\LinkHandler {
public function generateLink(&$content, $obj) {
// For other records than news, leave parameter unchanged
if ($obj->typolinkConfiguration['table'] != 'tx_news_domain_model_news') {
return;
}
$typolinkConfiguration = $obj->typolinkConfiguration;
// Get the news detail link from the reference page specified in the category
$selectFields = 'sys_category.single_pid';
$fromTables = 'tx_news_domain_model_news
LEFT JOIN sys_category_record_mm
ON tx_news_domain_model_news.uid = sys_category_record_mm.uid_foreign
AND tablenames = \'tx_news_domain_model_news\'
AND fieldname = \'categories\'
LEFT JOIN sys_category
ON sys_category.uid = sys_category_record_mm.uid_local';
$where = 'tx_news_domain_model_news.uid = ' . intval($obj->recordUid);
$rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
$selectFields,
$fromTables,
$where
);
if ($rows && count($rows) > 0 && $rows[0]['single_pid'] !='') {
$typolinkConfiguration['parameter'] = $rows[0]['single_pid'];
$obj->typolinkConfiguration = $typolinkConfiguration;
}
}
}
<?php
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkhandler']['generateLink'][] = 'EXT:<extname>/Classes/class.ext_linkhandler.php:ext_linkhandler->generateLink';
RTE.default.tx_linkhandler.tx_news {
label = Newsbeitrag
listTables = tx_news_domain_model_news
pageTreeMountPoints {
# storagepid of news entries
1 = 16
}
}
plugin.tx_linkhandler.tx_news {
// Do not force link generation when the news records are hidden or deleted.
forceLink = 0
typolink {
# fallback
parameter = 140
additionalParams = &tx_news_pi1[news]={field:uid}&tx_news_pi1[controller]=News&tx_news_pi1[action]=detail
additionalParams.insertData = 1
useCacheHash = 1
table = tx_news_domain_model_news
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment