Set Upload Folder when using FAL in TCA

1.3k views Asked by At

Is it possible when using FAL, to set the upload destination folder directly in the TCA column? My configuration looks like this at the moment:

'images_outdoor' => Array (
        'exclude' => 1,
        'label' => 'Outdoor: ',
        'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('images_outdoor', Array (
            'appearance' => Array (
                'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
            ),
            'minitems' => 1,
            'maxitems' => 6,
        ), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']),
    ),

I have such columns in different TCAs and want their images to be saved in different folders. So a standard folder setting doesn't work here.

1

There are 1 answers

1
Lasse On

I know this one is old but here is a answer.

There are no supported way for TYPO3 6.2, but in the new TYPO3 7.6 LTS it should be possible to register a hook in your ext_localconf.php file, add this:

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['getDefaultUploadFolder'][] = 'VendorName\ExtensionName\Hooks\BackendUserAuthentication->getDefaultUploadFolder'

Create the file Classes/Hooks/BackendUserAuthentication.php and write something like this:

<?php
namespace VendorName\ExtensionName\Hooks;

classe BackendUserAuthentication {
    public function getDefaultUploadFolder(Array $params, \TYPO3\CMS\Core\Authentication\BackendUserAuthentication $backendUserAuthentication) {
        // Do what you wants here and return a object of \TYPO3\CMS\Core\Resource\Folder
    }
}

The params array will contain this:

$_params = array(
    'uploadFolder' => $uploadFolder, // The current \TYPO3\CMS\Core\Resource\Folder object, properly 1:/user_upload/
    'pid' => $pid, // Page id
    'table' => $table, // The table name
    'field' => $field, // The field name
);

Now use the table and field name to change the upload folder - good look :)