spooner-web / tcabuilder
轻松维护和创建您的 TCA 表单的实用工具
3.3.0
2024-08-08 22:14 UTC
Requires
- php: >= 7.4, < 8.4
- typo3/cms-backend: ^v11.5 || ^v12.4 || ^v13.2
- typo3/cms-core: ^v11.5 || ^v12.4 || ^v13.2
Requires (Dev)
- phpunit/phpunit: ^9.5
- ssch/typo3-rector: ^2.4
This package is auto-updated.
Last update: 2024-09-08 22:30:22 UTC
README
它做什么?
使用 TCA 建造者,您可以轻松地以易于理解的方式创建或更改类型列表中的字段。
字段名称中的分号时间已经消失了。
例如
- 为内容元素或任何其他记录的表单组合字段列表
- 更改现有定义的类型
在 v1.6.0 中引入 TcaCreator
使用 TCA 创建者,您可以从头创建 TCA 表单,无需考虑默认字段的配置,如 ctrl
部分,或 columns
部分的默认字段。
更多示例请参见 示例部分
安装
通过 composer 安装
composer require spooner-web/tcabuilder
:warning: 在 composer 安装中,包不会在 typo3conf/ext 文件夹中,而是在 vendor 中
通过经典模式安装
- 前往 https://extensions.typo3.org/extension/tcabuilder
- 下载 ZIP 文件
- 使用非 composer 模式将其上传到您的 TYPO3 实例
通过扩展管理器安装
- 更新您的扩展列表
- 搜索“tcabuilder”
- 安装
Composer 无法检出此包
由于 composer 无法检测自托管 GitLab 实例的 ZIP 存档,当部署或构建使用此包的项目时可能会出现问题。
要修复此问题,您需要将 GitLab 内置 packagist API 添加到项目 composer.json 的 repositories
部分
{
"type": "composer",
"url": "https://git.spooner.io/api/v4/group/8/-/packages/composer/"
}
使用方法
通用用法
建议在您的扩展 Configuration/TCA/Overrides/
文件夹的 php 文件中使用 TcaBuilder
。
- 实例化
TcaBuilder
类 - 设置要配置的表和类型(也可能是一个尚不存在类型)
- 使用方法进行操作
- 保存到 TCA
- 刷新缓存
- 查看结果
方法
主要方法
方法名称 | 描述 | 参数 |
---|---|---|
setTable | 设置从其中加载配置的表 | string $tableName |
setType | 设置从其中加载配置的类型 | string $typeName |
load | 如果它是一个现有类型,则加载配置 | |
loadConfiguration | 一个简短的方法,可以一次性运行 setTable 、setType 和 load | string $tableNamestring $typeName |
useLocalLangFile | 设置一个用于标签的 locallang 文件(以 EXT: 开头) | string $localLangFile |
saveToTca | 将操作后的配置保存到 TCA | bool $resetAfterSave (可选) |
returnAsArray | 而不是保存配置,直接将其作为数组返回 |
操作类型
方法名称 | 描述 | 参数 |
---|---|---|
addField | 向选定的类型添加字段 | string $typeNamestring $position (可选)string $alternativeLabel (可选) |
removeField | 从选定的类型中删除字段 | string $fieldName |
moveField | 将字段移动到新位置(或使用新标签替换) | string $fieldNamestring $newPositionstring $newLabel (可选) |
addPalette | 向选定的类型添加现有的调色板 | string $paletteNamestring $position (可选)string $alternativeLabel (可选) |
removePalette | 从所选类型中移除调色板 | string $paletteName |
movePalette | 将调色板移动到新位置(或者使用新标签) | string $paletteNamestring $newPositionstring $newLabel (可选) |
addDiv | 向所选类型添加div(标签页) | string $divNamestring $label |
removeDiv | 从所选类型中移除div(标签页),可以通过位置(索引,从0开始)或标签来实现 | string |int $positionOrLabel |
addOverride | 添加字段的自定义覆盖 | string $fieldNamearray $configuration |
initialize | 使用空列表初始化类型 |
操作调色板
方法名称 | 描述 | 参数 |
---|---|---|
addCustomPalette | 创建新的调色板(可选地直接插入到指定位置) | string $paletteIdarray $fieldsstring $label (可选)string $position (可选) |
addFieldToPalette | 向调色板添加字段 | string $paletteIdstring $fieldstring $position (可选) |
removeFieldFromPalette | 从调色板中移除字段 | string $paletteIdstring $field |
initializePalette | 使用空列表初始化调色板 | string $paletteId |
辅助方法
方法名称 | 描述 | 参数 | 返回 |
---|---|---|---|
getPaletteString | 查找用于列表中的完整调色板字符串(用于在位置字符串中使用) | string $paletteName | string 包含--palette-- 和可能的标签配置的完整调色板字符串 |
getDivString | 查找用于列表中的完整div字符串(用于在位置字符串中使用),可以通过位置(索引,从0开始)或标签来实现 | string |int $positionOrLabel | string 包含--div-- 和div标签的完整div字符串 |
定位字段、调色板或div的可能值
值 | 描述 |
---|---|
before:<item> | 将项目移动到给定项目之前 |
after:<item> | 将项目移动到给定项目之后 |
replace:<item> | 替换给定项目 |
示例(TCA构建器)
添加自定义内容元素
$tcaBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\SpoonerWeb\TcaBuilder\TcaBuilder::class);
$tcaBuilder
->setTable('tt_content') // define table
->setType('test') // define type
->addDiv('General')
->addField('header', '', 'Top header!!')
->addField('bodytext')
->addField('subheader', 'after:header')
->addField('layout', 'before:header')
->addDiv('Extra')
->addPalette('access')
->addPalette('hidden', 'after:bodytext', 'Alternative label')
->saveToTca(); // save to TCA
更改现有配置
$tcaBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\SpoonerWeb\TcaBuilder\TcaBuilder::class);
$tcaBuilder
->setTable('pages') // define table
->setType(\TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_LINK) // define type
->load() // load definitions
->removeField('doktype')
->removePalette('external')
->removeDiv(1)
->addPalette('external', 'after:--palette--;;layout')
->saveToTca(); // save back to TCA
$tcaBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\SpoonerWeb\TcaBuilder\TcaBuilder::class);
$tcaBuilder
->loadConfiguration('pages', \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT)
->removeDiv('LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.tabs.metadata')
->movePalette('title', 'after:' . $tcaBuilder->getPaletteString('abstract'), 'New title')
->addOverride(
'title',
[
'label' => 'New title',
'config' => [
'renderType' => 'inputLink'
]
]
)
->saveToTca();
使用语言文件
$tcaBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\SpoonerWeb\TcaBuilder\TcaBuilder::class);
$tcaBuilder
->loadConfiguration('pages', \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT)
->useLocalLangFile('EXT:my_extension/Resources/Private/Language/locallang.xlf')
->addField('new_field', '', 'LANG:new_field') // Used label: "LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:new_field"
->saveToTca();
进行最小更改
$tcaBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\SpoonerWeb\TcaBuilder\TcaBuilder::class);
$tcaBuilder
->loadConfiguration('tt_content', 'textmedia')
->removePalette('headers')
->saveToTca();
示例(Tca Creator)
在自定义扩展内创建新表的TCA配置
// Returns the default values of ctrl section
// By default language, version and sorting options are set
// These options can be unset and additional overridden fields can be set
$configuration['ctrl'] = \SpoonerWeb\TcaBuilder\TcaCreator::getControlConfiguration(
'title',
'label'
);
// Returns the default columns depending on the ctrl section configuration
// Example: If ctrl section includes language, this method returns the field configuration
// for all language fields (sys_language_uid, l10n_parent, l10n_diffsource, l10n_source)
$configuration['columns'] = \SpoonerWeb\TcaBuilder\TcaCreator::getColumnsConfiguration(
$configuration['ctrl'],
'tx_extension_domain_model_record',
[
'title' => [
'label' => 'My label',
'config' => [
'type' => 'input'
]
]
]
);
// Uses TcaBuilder class to create the configuration for the TCA form
$configuration['types'][] = \SpoonerWeb\TcaBuilder\TcaCreator::buildTypesConfiguration()
->addDiv('General')
->addField('title')
->addField('subtitle')
->addDiv('Categories')
->addField('categories')
->returnAsArray();
// Now return TCA configuration
return $configuration;