【问题标题】:TYPO3 8.7: Extend sys_category with a new fieldTYPO3 8.7:使用新字段扩展 sys_category
【发布时间】:2018-03-06 16:26:37
【问题描述】:

我只是想用一个新的字段“page”来扩展 sys_category 表,这只是普通的 extbase 方式。像魅力一样工作,字段显示并保存在数据库中。但是我的 f:debug 在 Fluid 中没有字段。有人知道缺少什么吗?

非常感谢您的帮助!

TCA 覆盖:

$newColumns = [
  'page' => [
    'exclude' => true,
    'label' => 'LLL:EXT:project/Resources/Private/Language/Default/locallang_db.xlf:sys_category.page',
    'config' => [
      'type' => 'group',
      'internal_type' => 'db',
      'allowed' => 'pages',
      'size' => 1,
      'maxitems' => 1,
      'minitems' => 0
    ]
  ],
];


\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_category', $newColumns);

// Make fields visible in the TCEforms:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
  'sys_category', // Table name
  'page', // Field list to add
  '1', // List of specific types to add the field list to. (If empty, all type entries are affected)
  'after:title' // Insert fields before (default) or after one, or replace a field
);

SQL:

#
# Table structure for table 'sys_category'
#
CREATE TABLE sys_category (
  page int(11),
);

型号:

<?php
namespace <Vendorname>\Project\Domain\Model;

use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

/**
 * Class Category
 * @package <Vendorname>\Project
 */

class Category extends \TYPO3\CMS\Extbase\Domain\Model\Category
{
    /**
     * @var integer
     */
    protected $page = null;


    /**
     * Gets the page.
     *
     * @return integer
     * @api
     */
    public function getPage()
    {
        return $this->page;
    }

    /**
     * Sets the page.
     *
     * @param integer $page
     * @api
     */
    public function setPage($page)
    {
        $this->page = $page;
    }

}

排版设置:

config.tx_extbase.persistence {
    storagePid = {$plugin.tx_project.persistence.storagePid}
    classes {
        TYPO3\CMS\Extbase\Domain\Model\Category {
            subclasses {
                <Vendorname>\Project\Domain\Model\Category = <Vendorname>\Project\Domain\Model\Category
            }
        }

        <Vendorname>\Project\Domain\Model\Category {
            mapping {
                tableName = sys_category
            }
        }
    }
}

【问题讨论】:

  • 您找到解决问题的方法了吗?目前我想做同样的事情......

标签: typo3 extbase typo3-8.x typo3-extensions


【解决方案1】:

我不确定是否可以对 TYPO3 的 sys_category 表进行子类化。

如果您始终希望 所有查询TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository 将返回您的自定义类型的对象,您可以配置您的 ext_typoscript_setup,如下所示

config.tx_extbase{
    objects {
        TYPO3\CMS\Extbase\Domain\Model\Category.className = <vendor>\Project\Domain\Model\Category
    }
    persistence.classes {
        <vendor>\Project\Domain\Model\Category {
            mapping {
                tableName = sys_category
            }
        }
    }
}

请注意,这将不包括表sys_category 上由其他 TYPO3 扩展制作的任何其他扩展。

但是,如果您只需要扩展程序中的扩展 Category 对象而不是 TYPO3 中的全局对象,您可以在扩展程序中创建自己的 CategoryRepository,例如 ext:news

【讨论】:

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