首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何在TYPO3 / TCA覆盖中内联来自tt_content的包含标题、正文、图像的自定义内容元素?

在 TYPO3 / TCA 覆盖中内联来自 tt_content 的包含标题、正文、图像的自定义内容元素,您可以按照以下步骤进行操作:

  1. 创建一个新的扩展(Extension),可以使用 TYPO3 Extension Builder 或手动创建。
  2. 在新扩展的 Configuration/TCA/Overrides/tt_content.php 文件中进行覆盖。
  3. tt_content 表的 types 配置中添加一个新的元素类型。
  4. tt_content 表的 columns 配置中添加新的字段用于存储自定义内容元素的标题、正文和图像。
  5. 定义自定义内容元素的图像处理和上传规则。
  6. tt_content 表的 palettes 配置中添加图像字段,并设置显示方式和位置。
  7. tt_content 表的 types 配置中定义新元素类型的表单字段。
  8. tt_content 表的 types 配置中定义新元素类型的展示方式。
  9. tt_content 表的 ctrl 配置中添加新元素类型的图标。

下面是一个示例代码,用于 TYPO3 / TCA 覆盖中内联来自 tt_content 的包含标题、正文、图像的自定义内容元素:

代码语言:txt
复制
// Step 3: Add a new element type
$GLOBALS['TCA']['tt_content']['types']['custom_element'] = [
    'showitem' => '
        --palette--;;general,
        header; Custom Element Header,
        bodytext; Custom Element Bodytext,
        image; Custom Element Image,
    ',
];

// Step 4: Add new fields for custom element
$GLOBALS['TCA']['tt_content']['columns']['header'] = [
    'label' => 'Custom Element Header',
    'config' => [
        'type' => 'input',
        'size' => 30,
    ],
];
$GLOBALS['TCA']['tt_content']['columns']['bodytext'] = [
    'label' => 'Custom Element Bodytext',
    'config' => [
        'type' => 'text',
        'cols' => 40,
        'rows' => 15,
    ],
];
$GLOBALS['TCA']['tt_content']['columns']['image'] = [
    'label' => 'Custom Element Image',
    'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
        'image',
        ['maxitems' => 1],
        $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
    ),
];

// Step 5: Define image processing and upload rules
$GLOBALS['TCA']['tt_content']['columns']['image']['config']['foreign_types'] = [
    '0' => [
        'showitem' => '
            --palette--;;filePalette,
        ',
    ],
    \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
        'showitem' => '
            --palette--;;filePalette,
            --palette--;;imageoverlayPalette,
        ',
    ],
];

// Step 6: Add image field to palettes
$GLOBALS['TCA']['tt_content']['palettes']['filePalette'] = [
    'showitem' => 'file_external,',
];
$GLOBALS['TCA']['tt_content']['palettes']['imageoverlayPalette'] = [
    'showitem' => 'image_link, --linebreak--,
                    image_zoom, image_noWrap, image_effects',
];

// Step 7: Add form fields for new element type
$GLOBALS['TCA']['tt_content']['types']['custom_element']['showitem'] .= '
    --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.appearance,
    --palette--;;frames,
    --palette--;;appearanceLinks,
    --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.access,
    --palette--;;hidden,
    --palette--;;access,
    --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.extended,
';

// Step 8: Define display options for new element type
$GLOBALS['TCA']['tt_content']['types']['custom_element']['columnsOverrides'] = [
    'image' => [
        'config' => [
            'maxitems' => 1,
        ],
    ],
];

// Step 9: Add icon for new element type
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class)
    ->registerIcon(
        'content-custom_element',
        \TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
        ['source' => 'EXT:your_extension/Resources/Public/Icons/CustomElement.svg']
    );
$GLOBALS['TCA']['tt_content']['ctrl']['typeicon_classes']['custom_element'] = 'content-custom_element';

请注意,上述代码中的 your_extension 需要替换为您的扩展的名称。您还需要根据自己的需求调整字段的配置和显示方式。

希望这些步骤可以帮助您在 TYPO3 / TCA 覆盖中成功内联自定义内容元素的标题、正文和图像。对于 TYPO3 相关产品和详细介绍,请访问腾讯云的 TYPO3 产品页面:https://cloud.tencent.com/product/typo3

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的视频

领券