When using the new linkhandler in TYPO3 like the link below:
https://usetypo3.com/linkhandler.html
i only have one parameter for the detail page:
config.recordLinks.tx_news {
typolink {
parameter = {$myConstants.newsDetailPid}
}
}
How can ich change the linkhandler (hook etc.) in order to get the detail page from the news Category (sys category)?
Use the following code:
config.recordLinks.tx_news {
typolink {
parameter.stdWrap.cObject = CONTENT
parameter.stdWrap.cObject {
table = sys_category
select {
pidInList = 100
# pid of category records
max = 1
selectFields = sys_category.single_pid AS detailPid
join = sys_category_record_mm ON sys_category_record_mm.uid_local = sys_category.uid
where = sys_category_record_mm.uid_foreign = { field: uid }
where.insertData = 1
andWhere.stdWrap.intVal = 1
andWhere.stdWrap.stripHtml = 1
}
renderObj = TEXT
renderObj.field = detailPid
renderObj.wrap = |
}
additionalParams.data = field:uid
additionalParams.wrap = &tx_news_pi1[news]=|
useCacheHash = 1
}
}
You find the documentation of the linkhandler integration here: https://docs.typo3.org/typo3cms/extensions/core/8.7/Changelog/8.6/Feature-79626-IntegrateRecordLinkHandler.html
There you can see that you can specify an own class for the handling. No hooks are provided as far as I can see.
This is possible with the next upcoming version of ext:news, see this change for details.
By using the following TypoScript
config.recordLinks.tx_news {
typolink {
# Detail page
parameter.cObject = USER
parameter.cObject {
userFunc = GeorgRinger\News\Service\LinkHandlerTargetPageService->process
news.data = field:uid
# Page used if no detail page is set in the category
fallback = 123
}
additionalParams.data = field:uid
additionalParams.wrap = &tx_news_pi1[controller]=News&tx_news_pi1[action]=detail&tx_news_pi1[news]=|
}
}
and the according userfunc
<?php
declare(strict_types=1);
namespace GeorgRinger\News\Service;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/**
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
class LinkHandlerTargetPageService
{
/** @var ContentObjectRenderer */
public $cObj;
public function process(string $content = '', array $configuration = []): int
{
$fallbackPageId = (int)($configuration['fallback'] ?? 0);
$newsId = (int)$this->cObj->stdWrapValue('news', $configuration, null);
if ($newsId === 0) {
return $fallbackPageId;
}
$singlePid = $this->getSinglePidFromCategory($newsId);
return $singlePid ?: $fallbackPageId;
}
/**
* Obtains a pid for the single view from the category.
*
* @param int $newsId
* @return int
*/
protected function getSinglePidFromCategory(int $newsId): int
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_category');
$categoryRecord = $queryBuilder
->select('title', 'single_pid')
->from('sys_category')
->leftJoin(
'sys_category',
'sys_category_record_mm',
'sys_category_record_mm',
$queryBuilder->expr()->eq('sys_category_record_mm.uid_local', $queryBuilder->quoteIdentifier('sys_category.uid'))
)
->where(
$queryBuilder->expr()->eq('sys_category_record_mm.tablenames', $queryBuilder->createNamedParameter('tx_news_domain_model_news', \PDO::PARAM_STR)),
$queryBuilder->expr()->gt('sys_category.single_pid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('sys_category_record_mm.uid_foreign', $queryBuilder->createNamedParameter($newsId, \PDO::PARAM_INT))
)
->orderBy('sys_category_record_mm.sorting')
->setMaxResults(1)
->execute()->fetch();
return (int)$categoryRecord['single_pid'];
}
}
Of course you can copy the PHP Class to your site package and adopt the namespaces in the TS as well to have it working in your installation
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.