你如何在 TYPO3 中使用 type=inline 来创建重复字段?
How do you use type=inline in TYPO3 to create repeating fields?
在 TYPO3 中,我想制作一个允许用户在其中创建多个子块的元素。
例如:
Create New +
|
|- Sub Block
| |- Assets
| |- Text Field
|
|- Sub Block
| |- Assets
| |- Text Field
据我了解,这是使用 type='inline'
完成的
但是,文档假定您了解该过程的所有先前步骤,而且我没有找到关于此类元素的教程。
您可以使用扩展 mask
and mask_export
为您的内容元素类型生成扩展。
他们为您处理一切,从 table 增强到 table 声明,所有代码都在 mySQL 和 PHP 中(包括 TCA,getter/setter, ...).
如果您想自己做,请查看文档:
要添加与新记录(不是内容元素)有 1:n 关系的新内容元素,您必须添加新记录和 tt_content 的新 属性描述 tt_content 和您的记录之间的关系。
- 为您的新记录添加一个新的table
- 为您的新记录添加 TCA
- 允许在默认页面添加记录
- 扩展 table tt_content
- 为您的新内容元素添加 TCA
作为一个基本示例,我创建了一个新记录“my_list_item”和一个新内容元素“my_list”:
为您的新记录添加新的 table (ext_tables.sql):
CREATE TABLE tx_myext_domain_model_mylistitem (
parent_uid int(11) DEFAULT '0' NOT NULL,
parent_table varchar(255) DEFAULT '' NOT NULL,
title varchar(255) DEFAULT '' NOT NULL
);
描述 TCA 中的新记录 (Configuration/TCA/tx_myext_domain_model_mylistitem.php
<?php
return [
'ctrl' => [
'title' => 'Label',
'label' => 'title',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'sortby' => 'sorting',
'versioningWS' => true,
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'transOrigDiffSourceField' => 'l10n_diffsource',
'delete' => 'deleted',
'hideTable' => true,
'enablecolumns' => [
'disabled' => 'hidden',
],
'searchFields' => 'title',
],
'interface' => [
'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, title',
],
'columns' => [
'sys_language_uid' => [
'exclude' => true,
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'special' => 'languages',
'items' => [
[
'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.allLanguages',
-1,
'flags-multiple'
]
],
'default' => 0,
],
],
'l10n_parent' => [
'displayCond' => 'FIELD:sys_language_uid:>:0',
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.l18n_parent',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'default' => 0,
'items' => [
['', 0],
],
'foreign_table' => 'tx_myext_domain_model_mylistitem',
'foreign_table_where' => 'AND {#tx_myext_domain_model_mylistitem}.{#pid}=###CURRENT_PID### AND {#tx_myext_domain_model_mylistitem}.{#sys_language_uid} IN (-1,0)',
],
],
'l10n_diffsource' => [
'config' => [
'type' => 'passthrough',
],
],
't3ver_label' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.versionLabel',
'config' => [
'type' => 'input',
'size' => 30,
'max' => 255,
],
],
'hidden' => [
'exclude' => true,
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.visible',
'config' => [
'type' => 'check',
'renderType' => 'checkboxToggle',
'items' => [
[
0 => '',
1 => '',
'invertStateDisplay' => true
]
],
],
],
'title' => [
'exclude' => true,
'label' => 'Your header label',
'config' => [
'type' => 'input',
'size' => 30,
'eval' => 'trim,required'
],
],
'parent_uid' => [
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
[
'',
0,
],
],
'default' => 0,
'foreign_table' => 'tt_content',
'foreign_table_where' => 'AND tt_content.pid=###CURRENT_PID### AND tt_content.sys_language_uid IN (-1, ###REC_FIELD_sys_language_uid###)',
],
],
'parent_table' => [
'config' => [
'type' => 'passthrough',
],
],
],
'types' => [
'1' => ['showitem' =>
'--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general, title, bodytext, --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:language, sys_language_uid, l10n_parent, l10n_diffsource, --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access, hidden'
],
],
];
允许在页面上记录 (ext_tables.php):
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_myext_domain_model_mylistitem');
描述新记录的TCA与自身的关系(Configuration/TCA/Overrides/tt_content.php)
$myListItemTca = [
'tx_myext_mylist' => [
'exclude' => true,
'label' => 'Field label',
'config' => [
'appearance' => [
'collapseAll' => '1',
'enabledControls' => [
'dragdrop' => '1',
],
'levelLinksPosition' => 'bottom',
'useSortable' => '1',
],
'foreign_field' => 'parent_uid',
'foreign_table' => 'tx_myext_domain_model_mylistitem',
'foreign_table_field' => 'parent_table',
'maxitems' => '20',
'minitems' => '1',
'type' => 'inline',
],
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tt_content',
$myListItemTca
);
扩展 tt_content (ext_tables.sql)
CREATE TABLE tt_content (
tx_myext_mylist int(11) unsigned DEFAULT '0' NOT NULL,
);
添加新的内容元素 (Configuration/TCA/Overrides/tt_content.php):
$GLOBALS['TCA']['tt_content']['palettes']['mylist'] = array(
'showitem' =>
'tx_myext_mylist; Label',
'canNotCollapse' => 1
);
$GLOBALS['TCA']['tt_content']['types']['mylist'] = array(
'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
--palette--;;general,
--palette--;;headers,
--palette--;Label;mylist,
',
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
'CType',
[
'Title',
'mylist',
],
'textmedia',
'after'
);
这只是一个基本示例,减少并替换了我几周前制作的一个工作示例中的名称。如果我错过了什么,请评论。
顺便说一句:这与 mask / mask 导出处理 repeatable 元素的方式相同。所以当然你也可以使用 mask export 并根据自己的目的清理生成的代码(mask export 的代码很好用,但是有一点开销,因为它必须更通用)
在 TYPO3 中,我想制作一个允许用户在其中创建多个子块的元素。 例如:
Create New +
|
|- Sub Block
| |- Assets
| |- Text Field
|
|- Sub Block
| |- Assets
| |- Text Field
据我了解,这是使用 type='inline'
完成的但是,文档假定您了解该过程的所有先前步骤,而且我没有找到关于此类元素的教程。
您可以使用扩展 mask
and mask_export
为您的内容元素类型生成扩展。
他们为您处理一切,从 table 增强到 table 声明,所有代码都在 mySQL 和 PHP 中(包括 TCA,getter/setter, ...).
如果您想自己做,请查看文档:
要添加与新记录(不是内容元素)有 1:n 关系的新内容元素,您必须添加新记录和 tt_content 的新 属性描述 tt_content 和您的记录之间的关系。
- 为您的新记录添加一个新的table
- 为您的新记录添加 TCA
- 允许在默认页面添加记录
- 扩展 table tt_content
- 为您的新内容元素添加 TCA
作为一个基本示例,我创建了一个新记录“my_list_item”和一个新内容元素“my_list”:
为您的新记录添加新的 table (ext_tables.sql):
CREATE TABLE tx_myext_domain_model_mylistitem (
parent_uid int(11) DEFAULT '0' NOT NULL,
parent_table varchar(255) DEFAULT '' NOT NULL,
title varchar(255) DEFAULT '' NOT NULL
);
描述 TCA 中的新记录 (Configuration/TCA/tx_myext_domain_model_mylistitem.php
<?php
return [
'ctrl' => [
'title' => 'Label',
'label' => 'title',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'sortby' => 'sorting',
'versioningWS' => true,
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'transOrigDiffSourceField' => 'l10n_diffsource',
'delete' => 'deleted',
'hideTable' => true,
'enablecolumns' => [
'disabled' => 'hidden',
],
'searchFields' => 'title',
],
'interface' => [
'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, title',
],
'columns' => [
'sys_language_uid' => [
'exclude' => true,
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'special' => 'languages',
'items' => [
[
'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.allLanguages',
-1,
'flags-multiple'
]
],
'default' => 0,
],
],
'l10n_parent' => [
'displayCond' => 'FIELD:sys_language_uid:>:0',
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.l18n_parent',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'default' => 0,
'items' => [
['', 0],
],
'foreign_table' => 'tx_myext_domain_model_mylistitem',
'foreign_table_where' => 'AND {#tx_myext_domain_model_mylistitem}.{#pid}=###CURRENT_PID### AND {#tx_myext_domain_model_mylistitem}.{#sys_language_uid} IN (-1,0)',
],
],
'l10n_diffsource' => [
'config' => [
'type' => 'passthrough',
],
],
't3ver_label' => [
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.versionLabel',
'config' => [
'type' => 'input',
'size' => 30,
'max' => 255,
],
],
'hidden' => [
'exclude' => true,
'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.visible',
'config' => [
'type' => 'check',
'renderType' => 'checkboxToggle',
'items' => [
[
0 => '',
1 => '',
'invertStateDisplay' => true
]
],
],
],
'title' => [
'exclude' => true,
'label' => 'Your header label',
'config' => [
'type' => 'input',
'size' => 30,
'eval' => 'trim,required'
],
],
'parent_uid' => [
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
[
'',
0,
],
],
'default' => 0,
'foreign_table' => 'tt_content',
'foreign_table_where' => 'AND tt_content.pid=###CURRENT_PID### AND tt_content.sys_language_uid IN (-1, ###REC_FIELD_sys_language_uid###)',
],
],
'parent_table' => [
'config' => [
'type' => 'passthrough',
],
],
],
'types' => [
'1' => ['showitem' =>
'--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general, title, bodytext, --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:language, sys_language_uid, l10n_parent, l10n_diffsource, --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access, hidden'
],
],
];
允许在页面上记录 (ext_tables.php):
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_myext_domain_model_mylistitem');
描述新记录的TCA与自身的关系(Configuration/TCA/Overrides/tt_content.php)
$myListItemTca = [
'tx_myext_mylist' => [
'exclude' => true,
'label' => 'Field label',
'config' => [
'appearance' => [
'collapseAll' => '1',
'enabledControls' => [
'dragdrop' => '1',
],
'levelLinksPosition' => 'bottom',
'useSortable' => '1',
],
'foreign_field' => 'parent_uid',
'foreign_table' => 'tx_myext_domain_model_mylistitem',
'foreign_table_field' => 'parent_table',
'maxitems' => '20',
'minitems' => '1',
'type' => 'inline',
],
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tt_content',
$myListItemTca
);
扩展 tt_content (ext_tables.sql)
CREATE TABLE tt_content (
tx_myext_mylist int(11) unsigned DEFAULT '0' NOT NULL,
);
添加新的内容元素 (Configuration/TCA/Overrides/tt_content.php):
$GLOBALS['TCA']['tt_content']['palettes']['mylist'] = array(
'showitem' =>
'tx_myext_mylist; Label',
'canNotCollapse' => 1
);
$GLOBALS['TCA']['tt_content']['types']['mylist'] = array(
'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
--palette--;;general,
--palette--;;headers,
--palette--;Label;mylist,
',
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
'CType',
[
'Title',
'mylist',
],
'textmedia',
'after'
);
这只是一个基本示例,减少并替换了我几周前制作的一个工作示例中的名称。如果我错过了什么,请评论。
顺便说一句:这与 mask / mask 导出处理 repeatable 元素的方式相同。所以当然你也可以使用 mask export 并根据自己的目的清理生成的代码(mask export 的代码很好用,但是有一点开销,因为它必须更通用)