3

我为自定义内容元素制作了一个 extbase 扩展。由于这是我的第一个扩展,我从一个简单的“hello_world_ce”开始。这是我的文件:

ext_tables.php

<?php
$TCA['tt_content']['types']['hello_world_ce']['showitem'] = '--palette--;LLL:EXT:hello_world/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world.general;general, --palette--;LLL:EXT:hello_world/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world.header;header';

ext_localconf.php

<?php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:'.$_EXTKEY.'/Configuration/TypoScript/ModWizards.ts">');

ModWizards.ts

mod.wizards {
    newContentElement {
        wizardItems {
            hello_world {
                header = LLL:EXT:hello_world/Resources/Private/Language/locallang_mod.xlf:content_tab_header
                elements {
                    hello_world_ce {
                        icon = gfx/c_wiz/regular_header.gif
                        title = LLL:EXT:hello_world/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world
                        description = LLL:EXT:hello_world/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world.description
                        tt_content_defValues {
                            CType = hello_world_ce
                        }
                    }
                }
            }
            show = *
        }
    }
}

在 TYPO3 后端中,我看到了我的内容元素,可以将其添加到页面,但内容类型的下拉菜单显示INVALID VALUE ("hello_world_ce")

我错过了什么?

编辑:我找到了缺失的部分。我需要将我的内容类型添加到 CType 数组

ext_tables.php

$backupCTypeItems = $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'];
$GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'] = array(
    array(
        'LLL:EXT:'.$_EXTKEY.'/Resources/Private/Language/locallang_mod.xlf:content_tab_header',
        '--div--'
    ),
    array(
        'LLL:EXT:'.$_EXTKEY.'/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world',
        'hello_world_ce',
        'i/tt_content_header.gif'
    )
);
foreach($backupCTypeItems as $key => $value){
    $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'][] = $value;
}
4

1 回答 1

1

问题已被编辑,但我认为有更好的方法来实现解决方案。

只是为了清楚问题:

内容元素hello_world_ce未通过添加新内容元素添加到“类型”下拉列表中。

问题中的提示是正确的,它没有为 CType 字段定义。但是,您可以使用核心函数来代替操作数组:

 // Adds the content element to the "Type" dropdown
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPlugin(
   array(
      'LLL:EXT:your_extension_key/Resources/Private/Language/locallang_mod.xlf:content_element.hello_world',
      'hello_world_ce',
      'i/tt_content_header.gif'
   ),
   'CType',
   'your_extension_key'
);

这是一个非常好的示例,说明如何在TYPO3 7.6版本中添加您自己的内容元素。

注意:在 TYPO3 6.2 中也可以访问此功能。

于 2018-01-28T06:54:44.267 回答