How to create a sys_file_reference inside another sys_file_reference? - typo3

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

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

Add custom image field to tt_content

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.

How to integrate cropping variants in image manipulation tool in tx_news extension?

There's an awesome feature in TYPO3 8.7 called cropping variants in image manipulation tool. Details informations can be found in official feature description #75880. Thanks to this we can allow back-end user to crop one image in multiple variants, for exampple: for mobile and desktop. See image below.
Image from: https://techblog.sitegeist.de/responsive-images-with-typo3-8-7/
Configuration can be done in TCA:
'config' => [
'type' => 'imageManipulation',
'cropVariants' => [
'mobile' => [
'title' => 'LLL:EXT:ext_key/Resources/Private/Language/locallang.xlf:imageManipulation.mobile',
'allowedAspectRatios' => [
'4:3' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.4_3',
'value' => 4 / 3
],
'NaN' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.free',
'value' => 0.0
],
],
],
'desktop' => [
'title' => 'LLL:EXT:ext_key/Resources/Private/Language/locallang.xlf:imageManipulation.desktop',
'allowedAspectRatios' => [
'4:3' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.4_3',
'value' => 4 / 3
],
'NaN' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.free',
'value' => 0.0
],
],
],
]
]
I'm trying to integrate it into tx_news. I want to use existing field called fal_media. The configuration of this field you can find in the source file of tx_news in GitHub. Screenshot of the code snippet below:
Somebody have an idea how cropping variants in image manipulation can be implemented in tx_news extension for field fal_media?
Just to anwer this question and make it easy to find the solution (georgs link pointing to it)
$GLOBALS['TCA']['tx_news_domain_model_news']['columns']['fal_media']['config']['overrideChildTca']['columns']['crop'] = [
'config' => [
'cropVariants' => [
'mobile' => [
'title' => 'Mobile',
'allowedAspectRatios' => [
'4:3' => [
'title' => '4 zu 3',
'value' => 4 / 3
],
'NaN' => [
'title' => 'FREI',
'value' => 0.0
],
],
],
],
],
];
See: https://github.com/georgringer/news/issues/371
simply add cropVariant="mobile" to your f:image.