johndoe555
johndoe555

Reputation: 101

Typo3 10.4 - How to add FAL image to my extension

I'm a new Typo3 user and I'm trying to add images to my extension with using FAL.

I found some old docs and posts on stackoverflow to help me for adding FAL to add images, I'm using 10.4 version.

I configured my TCA, my locallang, and the model but the field doesn't appear in backend, the sources used were quite old I don't know if I missed something to make it works

I added it in my Configuration/TCA like that :

        'image' => [
            'exclude' => true,
            'label' => 'LLL:EXT:myextension/Resources/Private/Language/locallang_db.xlf:tx_myextension_domain_model_atelier.image',
            'config' =>
                \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
                    'image',
                    [
                        '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_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'
                            ]
                        ],
                        'foreign_match_fields' => [
                            'fieldname' => 'image',
                            'tablenames' => 'tx_myextension_domain_model_atelier',
                            'table_local' => 'sys_file',
                        ],
                        'maxitems' => 3
                    ],
                    $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
                ),

        ],

Language/locallang.xlf :

<trans-unit id="tx_myextension_domain_model_atelier.image">
   <source>image</source>
</trans-unit>

Model :

    /**
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
     */
    protected $image;


    /**
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $image
     */
    public function getImage()
    {
        return $this->image;
    }

    /**
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $image
     * @return void
     */
    public function setImage(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $image)
    {
        $this->image = $image;
    }

can someone tell me if i missed something, or if i made a mistake? thank you

Upvotes: 1

Views: 726

Answers (1)

Aristeidis Karavas
Aristeidis Karavas

Reputation: 1956

The first thing i can see that you are missing is whenever you use ObjectStorage, you have to initialise it first. That means, in your model, you have to do something like this:

/**
* Initializes all ObjectStorage properties when model is reconstructed from DB (where __construct is not called)
* Do not modify this method!
* It will be rewritten on each save in the extension builder
* You may modify the constructor of this class instead
*/
public function initializeObject()
{
   $this->image = $this->image ?? new ObjectStorage();
}

The second thing you have to do in order to display it in your Backend, you have to add it on the types. The types are responsible for the backend view, and you can configure the order which your columns, tabs and palettes are displayed.

return [
    'ctrl' => [...],
    'types' => [
        '0' => [
            'showitem' => 'hidden, image, sys_language_uid, l10n_parent, l10n_diffsource'
        ],
    ],
    'columns' => [...]
];

Upvotes: 1

Related Questions