代码之家  ›  专栏  ›  技术社区  ›  webman

typo3:tx_news获取be列表中自定义标题的系统类别系统类别

  •  1
  • webman  · 技术社区  · 7 年前

    我扩展了tx_news,开设了一些课程。有些课程针对不同的论据(我选择这些论据作为系统类别)处理同一主题。这意味着它们的标题是相同的,现在我试图通过在列表中包含选定的类别来使列表更适合编辑器…

    在中暗示自定义标题 Configuration/TCA/Overrides/tx_news_domain_model_news.php :

    $GLOBALS['TCA']['tx_news_domain_model_news']['ctrl']['label_userFunc'] = 'Vendor\\NewsExt\\Userfuncs\\Tca->customTitle';
    

    目前为止的用户函数 Classes/Userfuncs/Tca.php :

    <?php
    namespace Vendor\NewsExt\Userfuncs;
    
    use GeorgRinger\News\Domain\Model\News;
    
    /**
     * Class Tca
     */
    class Tca
    {
        /**
         * Loads a custom title for the news list view
         *
         * @return void
         */
        public function customTitle(
            &$parameters,
            $parentObject
        ){
            $record = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($parameters['table'], $parameters['row']['uid']);
            $newTitle = $record['title'];
            if($record['is_course']){
                $newTitle .= ' (' . $record['categories'] . ')' ;
            }
            $parameters['title'] = $newTitle;
        }
    }
    

    这显然给出了所选类别的数量…我没有包括我的任何尝试,因为它们不会导致任何结果…

    2 回复  |  直到 7 年前
        1
  •  1
  •   René Pflamm    7 年前

    您可以进行mm查询以解析分配的类别标题:

    <?php
      namespace Vendor\NewsExt\Userfuncs;
    
      use GeorgRinger\News\Domain\Model\News;
    
      /**
       * Class Tca
       */
      class Tca
      {
        /**
         * Loads a custom title for the news list view
         *
         * @return void
         */
        public function customTitle(&$parameters, $parentObject)
        {
          # fetch all categories assigned to this news
          $result = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query(
            'sys_category.uid, sys_category.title',
            'sys_category',
            'sys_category_record_mm',
            $parameters['table'],
            'AND sys_category_record_mm.tablenames = "' . $parameters['table'] . '" ' .
            'AND sys_category_record_mm.fieldname = "categories" ' .
            'AND sys_category_record_mm.uid_foreign = ' . $parameters['row']['uid']
          );
    
          # walk the categories an get the title of them
          $categoriesLabels = [];
          foreach ($result->fetch_all(MYSQLI_ASSOC) as $category) {
            $categoriesLabels[] = $category['title'];
          }
    
          # if at least one category put them into the title
          if (!empty(array_filter($categoriesLabels))) {
            $record = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($parameters['table'], $parameters['row']['uid']);
            $parameters['title'] = $record['title'] . ' ('. implode(', ', $categoriesLabels) .')';
          }
        }
      }
    

    注: 此代码在typo3 8.7.12中测试。

        2
  •  -1
  •   David user10336229    7 年前

    可能您必须在自己的存储库中进行自定义数据库查询,在该存储库中请求每个应用类别获取标题。

    有可能您可以使用tx新闻库来避免冗余代码,但是您必须包含一些代码/函数,这些代码/函数正在实例化请求——请求发往何处。