1
votes

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'
);
1
Can you share your PHP code from within Overrides/tt_content.php? I also do not fully understand if it is not possible to select an image and store it, or if it is only an issue to retrieve the image in frontend.Daniel
I've added the code from Overrides/tt_content.phpkurt
Thanks, can you answer my 2nd question? Also did you add an ext_tables.sql or adjust the existing one with a new column for your new field tx_pnbase_icon?Daniel
Sorry, didn't realize your second question; but I'm very grateful that you are willing to help me! I'm going to extend my original question.kurt
It is very strange; now suddenly I can choose an image and save it !? But how do I get the correct original image file, and not only a "1" in frontend?kurt

1 Answers

1
votes

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.