如何在TYPO3 10.4中创建用于上传PDF文件到SQL `mediumblob`的TCA字段。

huangapple go评论60阅读模式
英文:

How to create a TCA field for uploading a PDF file to SQL `mediumblob` in TYPO3 10.4

问题

您正在尝试找到一种解决方案,允许用户通过TCA上传PDF文件。上传的文件不应该与sys_file_reference创建关联。

您的当前TCA代码:

'pdf_data' => [
    'exclude' => true,
    'label' => 'PDF文件',
    'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
        'pdf_file',
        [
            'appearance' => [
                'createNewRelationLinkTitle' => '添加PDF文件',
            ],
            'maxitems' => 1,
            'minitems' => 0,
            'overrideChildTca' => [
                'types' => [
                    '0' => [
                        'showitem' => '
                        --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                        --palette--;;filePalette'
                    ],
                    \TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
                        'showitem' => '
                        --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                        --palette--;;filePalette'
                    ],
                    \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
                        'showitem' => '
                        --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                        --palette--;;filePalette'
                    ],
                    \TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => [
                        'showitem' => '
                        --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                        --palette--;;filePalette'
                    ],
                    \TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => [
                        'showitem' => '
                        --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                        --palette--;;filePalette'
                    ],
                    \TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [
                        'showitem' => '
                        --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                        --palette--;;filePalette'
                    ],
                ],
            ],
            'filter' => [
                '0' => [
                    'parameters' => [
                        'allowedFileExtensions' => 'pdf'
                    ]
                ]
            ],
            'default' => null,
        ],
        'pdf'
    ),
]

如果需要进一步的解释或修改,请告诉我。

英文:

I am trying to find solution, that will allow user to upload PDF file via TCA. Uploaded file musn't create relation with sys_file_reference.

My current code in TCA:

    'pdf_data' => [
'exclude' => true,
'label' => 'PDF file',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'pdf_file',
[
'appearance' => [
'createNewRelationLinkTitle' => 'Add PDF file',
],
'maxitems' => 1,
'minitems' => 0,
'overrideChildTca' => [
'types' => [
'0' => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
],
],
'filter' => [
'0' => [
'parameters' => [
'allowedFileExtensions' => 'pdf'
]
]
],
'default' => null,
],
'pdf'
),
]
],

答案1

得分: 0

虽然Thomas已经说过,将PDF文件存储在数据库中是非常不常见的,您确实需要一个充分的理由,但您仍然可以尝试通过TCA列类型user来提供自己的表单引擎渲染。

https://docs.typo3.org/m/typo3/reference-tca/10.4/en-us/ColumnsConfig/Type/User.html

只需确保提供一个渲染类型,该类型将返回有关存储的数据的基本信息,以便后端用户能够方便地处理这些文件。

此外,您可能还希望在数据存储时处理数据,因此还需要为DataHandler提供方法。

https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Typo3CoreEngine/Introduction/Index.html

英文:

Although Thomas already stated, that it is very uncommon and you really need a good reason to store PDF files in a database, you could still try to provide your own form engine rendering via TCA column type user

https://docs.typo3.org/m/typo3/reference-tca/10.4/en-us/ColumnsConfig/Type/User.html

Just make sure to provide a render type, that will return basic information about the stored data, so that BE users will get a convenient user interface to deal with the files.

Additionally you might want to deal with the data while it gets stored, so providing methods for the DataHandler would be necessary too.

https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Typo3CoreEngine/Introduction/Index.html

huangapple
  • 本文由 发表于 2023年1月9日 17:56:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055594.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定