Add custom image field to tt_content - typo3

how can I add a custom image field to tt_content correctly ? I made the first part with Overrides/tt_content.php and in ext_tables.sql, and thus I can see the new field in the backend, and in the frontend context I get data.tx_pnbase_icon.
But it is not possible for me to choose an image in the backend, nor will it be saved, even if the popup with the file list works.
Do I have to tell tt_content to connect the field with sys_file_reference (in Typoscript) ?
Or, do I even have to extend the Content model ?
Field in backend
<?php
$temporaryColumn = array(
'tx_pnbase_icon' => [
'label' => 'Icon für Inhalt',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'tx_pnbase_icon',
[
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFilegallery'
],
'foreign_types' => [
'0' => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_gallery.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_gallery.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_gallery.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_gallery.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_gallery.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_gallery.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
]
],
'foreign_match_fields' => [
'fieldname' => 'tx_pnbase_icon',
'tablenames' => 'tt_content',
'table_local' => 'sys_file',
],
'maxitems' => 1
],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
],
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tt_content',
$temporaryColumn
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
'tt_content',
'appearanceLinks', // layout
'tx_pnbase_icon',
'after:layout' // 'after:' layout
);
In ext_tables.sql
CREATE TABLE tt_content (
tx_pnbase_icon int(11) unsigned NOT NULL default '0'
);

TYPO3 by default will only store the number of relations inside the columns.
In case you are working with TypoScript FLUIDTEMPLATE, you can use data processing to resolve file relations. See https://docs.typo3.org/m/typo3/reference-typoscript/10.4/en-us/ContentObjects/Fluidtemplate/Index.html#dataprocessing for an overview of the concept, and https://github.com/TYPO3/TYPO3.CMS/blob/10.4/typo3/sysext/frontend/Classes/DataProcessing/FilesProcessor.php for the concrete processor to use. All processors have an example usage in their PHPDoc.
In case you use plain TypoScript, you should be able to use the FILES cObject: https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/ContentObjects/Files/Index.html#cobj-files.
https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/Fal/UsingFal/Frontend.html contains the whole overview of how to retrieve files.

Related

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

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'
),
]
],
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

TYPO3: add maxitems = 1 to an image selection for a backend module

I use the following code to make an image selection available in the backend:
(TYPO3 docs - inline - File Abstraction Layer)
'image' => [
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.images',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'image',
[
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
],
// custom configuration for displaying fields in the overlay/reference table
// to use the image overlay palette instead of the basic overlay palette
'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'
],
],
],
],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
],
I want to limit the selection to 1 item which should be:
TYPO3 dosc - maxitems option
image => [
'config' => [
'maxitems' => 1,
],
],
I cannot find how to add that ... all I tried gives errors
Sometimes, you just have to find the matching part of documentation...
File abstraction layer (FAL)
The API call is \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(). The first argument is the name of the current field, the second argument is an override configuration array, (...)
So it should do with overriding a part of the generated configuration by:
'image' => [
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.images',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'image',
[
'maxitems' => 1
]
)
]

TYPO3 Delete FileReference as non admin

I can't figure out which setting I have to activate to allow non-admin users to delete file references in the backend.
As admin I have that little trash icon which is missing when logged in as non-admin user.
I set every single flag to allow data manipulation in the backend users module but nothing worked so far. The only option is to give the user admin privileges. What do I miss?
Edit:
I am on TYPO3 10.4
Edit:
TCA for field:
'image' => [
'exclude' => true,
'label' => 'Image',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'image',
[
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference'
],
'foreign_types' => [
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
]
],
'foreign_match_fields' => [
'fieldname' => 'image',
'tablenames' => 'tx_association_domain_model_association',
'table_local' => 'sys_file',
],
'maxitems' => 1,
'minitems' => 0
],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
],

How to create a sys_file_reference inside another sys_file_reference?

I need to add some track files to a TYPO3 file reference. So I extended the TCA for sys_file_reference and added some fields. One of the fields should be a reference to another file.
It works as far that I can chose a file in the backend
Unfortunately, I can't save if I have a track added. TYPO3 throws me an exception.
#1300098528 InvalidArgumentException Incorrect reference to original file given for FileReference.
This exceptions happens because uid_local of the track reference is 0. But I don't know why this is 0 and how to fix it.
This is my TCA Configuration
'tx_eos_video_tracks' => [
'exclude' => 1,
'label' => 'Track files',
'description' => 'captions, chapters, descriptions, metadata, subtitles',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('tx_eos_video_tracks', [
'appearance' => [
'createNewRelationLinkTitle' => 'Add Track'
],
'overrideChildTca' => [
'types' => [
'0' => [
'showitem' => '
--palette--;;tx_eos_video_tracks_palette'
]
],
],
], 'vtt,srt')
],
Ok, I found the Solution. There must be always the fields uid_local, hidden, sys_language_uid, l10n_parent in the Child TCA.
There is a predefined palette ('filePalette') which adds the fields without showing them to the user.
So Changing
'overrideChildTca' => [
'types' => [
'0' => [
'showitem' => '
--palette--;;tx_eos_video_tracks_palette'
]
],
],
to
'overrideChildTca' => [
'types' => [
'0' => [
'showitem' => '
--palette--;;tx_eos_video_tracks_palette,
--palette--;;filePalette'
]
],
],
resolves my Issue

Problem with file upload TCA after upgrading to TYPO3 10

On typo3v9 i had working file upload field with this TCA configuration:
'image' => [
'exclude' => 0,
'label' => 'image upload',
'config' => [
'type' => 'group',
'internal_type' => 'db',
'uploadfolder' => 'uploads/folder',
'show_thumbs' => 1,
'size' => 5,
'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
'disallowed' => '',
],
],
i get this result:
but after migration to typo3v10 it does not work properly and give this result:
Someone have working solution for single file upload field?
I guess you mean internal_type=file ? That's deprecated. Here an example for image upload. However you can allow other types here too, I am sure you can find more info on that.
'photos' => [
'exclude' => true,
'label' => 'LLL:EXT:xxx/Resources/Private/Language/locallang_db.xlf:tx_xxx_domain_model_activity.photos',
'config' =>
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'photos',
[
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference'
],
'foreign_types' => [
'0' => [
'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'
]
],
'maxitems' => 30
],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
],