Skip to content

Instantly share code, notes, and snippets.

@ErHaWeb
Last active May 13, 2024 11:39
Show Gist options
  • Save ErHaWeb/b29f755451721b905bd474738928c1da to your computer and use it in GitHub Desktop.
Save ErHaWeb/b29f755451721b905bd474738928c1da to your computer and use it in GitHub Desktop.
Customize allowed file extensions

Customization of allowed file extensions for individual DB fields

With the following code you are able to remove file extensions from the list of allowed file extensions in field tx_news_domain_model_news.fal_media. Just edit the array $removeFileExtensionsArray and copy the code into file: EXT:<your_sitepackage>/Configuration/TCA/Overrides/tx_news_domain_model_news.php of your sitepackage.

<?php
defined('TYPO3') or die('Access denied.');
/*
* With the following code you are able to remove file extensions from the list
* of allowed file extensions in `field tx_news_domain_model_news`.`fal_media`.
* Just edit the array $removeFileExtensionsArray and copy the code into file:
* EXT:<your_sitepackage>/Configuration/TCA/Overrides/tx_news_domain_model_news.php
* of your sitepackage.
*/
call_user_func(static function () {
/*
* Array of file extensions that should be removed from the default file extensions list
*/
$removeFileExtensionsArray = [
'mp3',
'wav',
'mp4',
'ogg',
'flac',
'opus',
'webm',
'youtube',
'vimeo'
];
/*
* Convert list of default file extensions to array
*/
$allowedFileExtensionsArray = explode(
',',
$GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext']
);
/*
* Remove file extensions from default file extensions
*/
$allowedFileExtensionsArray = array_diff(
$allowedFileExtensionsArray,
$removeFileExtensionsArray
);
/*
* Convert array of allowed file extensions back to comma separated list
*/
$allowedFileExtensions = implode(
',',
$allowedFileExtensionsArray
);
/*
* Apply new list of allowed file extensions to TCA
*/
\TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule(
$GLOBALS['TCA']['tx_news_domain_model_news']['columns']['fal_media']['config'],
[
'overrideChildTca' => [
'columns' => [
'uid_local' => [
'config' => [
'appearance' => [
'elementBrowserAllowed' => $allowedFileExtensions
]
]
]
]
],
'filter' => [
[
'parameters' => [
'allowedFileExtensions' => $allowedFileExtensions
]
]
]
]
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment