首页 > 解决方案 > 在“文件/链接上传”中添加新字段 tt_content

问题描述

我使用File Links [uploads]Content Element 来显示文件列表,我需要在这个 CE 上添加一个字段来显示描述。

我在文档中找到了这个:https ://docs.typo3.org/m/typo3/reference-coreapi/8.7/en-us/ExtensionArchitecture/ExtendingTca/Examples/#example-2-extending-the-tt-content-表,但由于缺乏 PHP 和 T3 自定义技能,我无法应用它。

我应该在哪个文件中添加以下代码:

CREATE TABLE tt_content (
    tx_files_description tinyint(4) DEFAULT '0' NOT NULL
);

如何自定义以下代码?:

$temporaryColumn = array(
    'tx_files_description' => array (
            'exclude' => 0,
            'label' => 
'LLL:EXT:examples/Resources/Private/Language/locallang_db.xlf:tt_content.tx_files_description',
            'config' => array (
                    'type' => 'check',
            )
    )
 );
  \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
    'tt_content',
    $temporaryColumn
  );
 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
    'tt_content',
    'visibility',
    'tx_files_description',
    'after:linkToTop'
 );

标签: typo3-9.x

解决方案


Since you created your own content element i can not really know how to position the lement, but what i can do is to help you create it. I just tested on my TYPO3 installtion and it works.

ext_tables.sql

CREATE TABLE tt_content (
    tx_files_description text,
);

yourExtension/Configuration/TCA/Overrides/tt_content.php

$temporaryColumn = [
'tx_files_description' => [
    'exclude' => true,
    'label' => 'LLL:EXT:your_extension_key/Resources/Private/Language/locallang.xlf:tt_content.tx_files_description',
    'config' => [
        'type' => 'text',
        'enableRichtext' => false,
    ],
 ],
];

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
   'tt_content',
   $temporaryColumn
 );

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
   'tt_content',
   'tx_files_description',
   'general',
   'before:media'

 );

Assuming that you re using TYPO3 v9 go to the module Maintenance and press Analyze Database, then clear all cache.

If you are on TYPO3 v7-v8 then go to the install module and Run compare database (something like that). Clear the cache.

Then on your extended tab:

enter image description here

Best regards


推荐阅读