【问题标题】:news linkhandler (TYPO 8) and detailpage from category新闻链接处理程序(TYPO 8)和类别中的详细信息页面
【发布时间】:2017-10-10 19:12:58
【问题描述】:

在 TYPO3 中使用新的链接处理程序时,如下面的链接:

https://usetypo3.com/linkhandler.html

详情页只有一个参数:

config.recordLinks.tx_news {
    typolink {
        parameter = {$myConstants.newsDetailPid}
}
}

如何更改链接处理程序(钩子等)以便从新闻类别(sys 类别)中获取详细信息页面?

【问题讨论】:

    标签: typo3 tx-news typo3-8.x


    【解决方案1】:

    使用以下代码:

    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
        }   
    }   
    

    https://www.clickstorm.de/blog/linkhandler-typo3/

    【讨论】:

    • 虽然此代码可能会回答问题,但提供有关此代码为何和/或如何回答问题的额外上下文可提高其长期价值。此外,请添加您链接到帖子的页面中的要点(特别是因为您链接的页面是德语)。
    【解决方案2】:

    您可以在此处找到链接处理程序集成的文档: https://docs.typo3.org/typo3cms/extensions/core/8.7/Changelog/8.6/Feature-79626-IntegrateRecordLinkHandler.html

    在那里你可以看到你可以为处理指定一个自己的类。据我所知,没有提供任何挂钩。

    【讨论】:

    • 即使你改变了类:TCEMAIN.linkHandler.tx_news { #handler = TYPO3\CMS\Recordlist\LinkHandler\RecordLinkHandler handler = Vendor\YourExt\Hooks\RecordLinkHandler 你不能改变链接的处理.链接建在这里:github.com/TYPO3/TYPO3.CMS/blob/master/typo3/sysext/frontend/…我真的不知道如何根据自己的规则更改链接。
    【解决方案3】:

    下一个即将发布的 ext:news 版本可以实现这一点,详情请参阅change

    通过使用以下 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]=|
        }
    }
    

    以及相应的用户函数

    <?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'];
        }
    
    }
    

    当然,您可以将 PHP 类复制到您的站点包中,并采用 TS 中的命名空间以使其在您的安装中运行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多