【问题标题】:custom content element containing child elements of type inline with fields of tt_content(image, header) in TYPO3 9? TCA, Domain model needed?自定义内容元素包含与 TYPO3 9 中的 tt_content(image, header) 字段内联类型的子元素? TCA,需要领域模型吗?
【发布时间】:2021-08-07 17:26:17
【问题描述】:

我想使用 TYPO3 v9.5 核心制作一个自定义内容元素,该元素具有内联类型的自定义内容元素(子元素)。他们每个人都有来自 tt_content 的字段标题和图像。

所以我已经得到的是: custom content element with inline child

通过单击展开子元素,我得到如下内容: expanded child element with image and header field

到目前为止,一切都很好,但是当我查看我的页面内容时,为什么我的孩子不在父元素中: I want them childrens to be in the parent container, but they are next to it.

我的另一个问题是,我怎样才能让父元素及其所有子元素进入流动状态,以便我可以遍历子元素,例如将它们作为列表项输出。所有子代都有父代的 UID。

并且请不要告诉我使用扩展...我想学习 TYPO3 并使用 TYPO3 核心构建它:) 为了练习。

这就是我在 TCA/overrides 中的 tt_content 的样子:

对不起变量名......但我正在努力奋斗。可能有点难以理解:

    'tt_content',
    'CType',
    ['custom element', 'portfolio_list', 'content-text'],
    'textmedia',
    'after'
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
    'tt_content',
    'CType',
    ['custom element', 'portfolio_list2', 'content-text'],
    'textmedia',
    'after'
);

// $GLOBALS['TCA']['tt_content']['types']['portfolio_list'] = [
//     'showitem' => '
//          --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
//             --palette--;;general,
//             image; Image,
//             header; Title,

//             bodytext; Schreiben Sie einen Text,

//          --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access,
//             --palette--;;hidden,
//             --palette--;;access,
//       ',
//     'columnsOverrides' => [
//         'bodytext' => [
//             'config' => [
//                 'enableRichtext' => true,
//                 'richtextConfiguration' => 'default',
//             ],
//         ],
//     ],
// ];
$GLOBALS['TCA']['tt_content']['types']['portfolio_list2'] = [
    'showitem' => '
          --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
             --palette--;;general,
             image; Image,
             header; Title,
          
             portfolio_list2;Elemente,
             
          --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access,
             --palette--;;hidden,
             --palette--;;access,
       ',
    'columnsOverrides' => [
        'bodytext' => [
            'config' => [
                'enableRichtext' => true,
                'richtextConfiguration' => 'default',
            ],
        ],
        'portfolio_list2' => [
            'exclude' => true,
            'label' => 'Einzelnes-Portfolio',
            'config' => [
                'type' => 'inline',
                'allowed' => 'tt_content',
                'foreign_table' => 'tt_content',
                'foreign_sortby' => 'sorting',
                'foreign_field' => 'portfolio_list',
                'minitems' => 0,
                'maxitems' => 99,
                'appearance' => [
                    'collapseAll' => true,
                    'expandSingle' => true,
                    'levelLinksPosition' => 'bottom',
                    'useSortable' => true,
                    'showPossibleLocalizationRecords' => true,
                    'showRemovedLocalizationRecords' => true,
                    'showAllLocalizationLink' => true,
                    'showSynchronizationLink' => true,
                    'enabledControls' => [
                        'info' => false,
                    ],
                ],
            ],
        ],
    ],
];

// $GLOBALS['TCA']['tt_content']['columns']['header']['config']=[
//     'type' => 'inline',
//     'foreign_table' => 'tt_content',
//     'foreign_field' => 'header',
//     'foreign_sortby' => 'sorting',
//     'maxitems' => 9999,
//     'appearance' => [
//         'collapseAll' => 0,
//         'levelLinksPosition' => 'top',
//         'showSynchronizationLink' => 1,
//         'showPossibleLocalizationRecords' => 1,
//         'useSortable' => 1,
//         'showAllLocalizationLink' => 1
//     ]
// ];
// $GLOBALS['TCA']['tt_content']['columns']['bodytext']['config']=[
//     'type' => 'inline',
//     'foreign_table' => 'tt_content',
//     'foreign_field' => 'header',
//     'foreign_sortby' => 'sorting',
//     'maxitems' => 9999,
//     'appearance' => [
//         'collapseAll' => 0,
//         'levelLinksPosition' => 'top',
//         'showSynchronizationLink' => 1,
//         'showPossibleLocalizationRecords' => 1,
//         'useSortable' => 1,
//         'showAllLocalizationLink' => 1
//     ]
// ];
// $GLOBALS['TCA']['tt_content']['columns']['image']['config']=[
//     'type' => 'inline',
//     'foreign_table' => 'tt_content',
//     'foreign_field' => 'image',
//     'foreign_sortby' => 'sorting',
//     'maxitems' => 9999,
//     'appearance' => [
//         'collapseAll' => 0,
//         'levelLinksPosition' => 'top',
//         'showSynchronizationLink' => 1,
//         'showPossibleLocalizationRecords' => 1,
//         'useSortable' => 1,
//         'showAllLocalizationLink' => 1
//     ]
// ];

$temporaryColumn = [
    'portfolio_list2' => [
        'exclude' => true,
        'label' => 'Einzelnes-Portfolio',
        'config' => [
            'type' => 'inline',
            'allowed' => 'tt_content',
            'foreign_table' => 'tt_content',
            'foreign_sortby' => 'sorting',
            'foreign_field' => 'portfolio_list',
            'minitems' => 0,
            'maxitems' => 99,
            'appearance' => [
                'collapseAll' => true,
                'expandSingle' => true,
                'levelLinksPosition' => 'bottom',
                'useSortable' => true,
                'showPossibleLocalizationRecords' => true,
                'showRemovedLocalizationRecords' => true,
                'showAllLocalizationLink' => true,
                'showSynchronizationLink' => true,
                'enabledControls' => [
                    'info' => false,
                ],
            ],
        ],
    ],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
    'tt_content',
    $temporaryColumn
);

//  $customImage = [
//     'portfolio_list' => [

//         'exclude' => true,
//         'label' => 'Einzelnes-Portfolio',
//         'config' => [
//             'type' => 'inline',
//             'foreign_table' => 'tt_content',
//             'foreign_field' => 'teaser_field',
//             'foreign_sortby' => 'sorting',
//             'maxitems' => 9999,
//             'appearance' => [
//                 'collapseAll' => 0,
//                 'levelLinksPosition' => 'top',
//                 'showSynchronizationLink' => 1,
//                 'showPossibleLocalizationRecords' => 1,
//                 'useSortable' => 1,
//                 'showAllLocalizationLink' => 1
//             ],
//         ],

//     ],
//  ];
//  \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content', $customImage);


Do I need Domain Models and make a 1:n relation or something like that? Sorry, for stupid questions. I am 2.5 months into TYPO3 and I just start my career in coding :)

I would be so thankful for any kind of help :) THX a lot!

【问题讨论】:

  • 我不知道你是否可以单独使用 TYPO3...你可以使用像 gridelements 或容器这样的扩展来“嵌套”另一个内容元素中的 tt_content 内容元素;另一种选择是在不同的自定义表上定义您的子元素;看一下扩展 EXT:bootstrap_package,其中包含此类元素的几个示例(卡片、轮播...);这是一个关于如何制作自己的网站包扩展的金矿。
  • 例如 TCA stackoverflow.com/questions/68691660/…。请注意,如果孩子有资产或图像,您需要一个双嵌套数据处理器

标签: typo3 typoscript fluid typo3-9.x typo3-extensions


【解决方案1】:

在前端获取内容元素值所需的是数据处理。 DataProcessing 基本上是由 TypoScript 完成的 SQL 查询。在这里,您可以找到有关如何构建自定义元素的详细教程。有一节用一个例子来解释数据处理。

How to create custom content elements on TYPO3

这里是官方文档

DataProcessing

对于在后端显示的孩子,您可以通过为插件预览创建一个 Hook 来隐藏它们。在我发给你的文章中,有一个关于如何创建钩子的详细说明。它被称为“PageLayoutView Hook”这是官方文档

Configure Custom Backend Preview for Content Element

一旦你创建了类,为了隐藏孩子,你必须添加这个:

New hook to determine if content record is used/unused

您需要做的是将子项留在colPos=0 并将函数编辑为return $record['colPos'] === 0,或者您可以在布局上创建一个新的后端字段,为其提供 999 colPos 编号(或您想要的任何编号,这并不重要)并保持功能不变。但是你必须记住,当一个新的孩子被创建时,你必须自动给它在你的函数中定义的 colPos,否则编辑器每次都必须手动选择 colPos 999。您可以根据自己的需要对其进行编辑来实现:

$GLOBALS['TCA']['tx_news_domain_model_news']['columns']['content_elements']['config']['overrideChildTca']['columns']['colPos']['config']['default'] = '1';

希望它有所帮助。其他问题,欢迎提问

最好的问候

【讨论】:

  • 弃用:#90348 - PageLayoutView 类.. 我猜你的钩子可能工作到 9.5。
  • 它在 TYPO3 10 中被弃用,这意味着它很可能会在 TYPO3 12 之前工作。一般来说,如果某些东西被标记为弃用,它将在两个主要版本之后被删除
猜你喜欢
  • 2017-07-24
  • 1970-01-01
  • 2021-01-22
  • 2018-05-24
  • 1970-01-01
  • 2015-05-02
  • 2023-03-10
  • 2021-06-18
  • 1970-01-01
相关资源
最近更新 更多