I hope anyone can help me to add a custom field for media&image element.
I create a custom content element with a extension "sitepackage builder". I want to add a field for a media element with my new variable.
I want to add like this:
The media element should be able to upload images (e.g. jpeg, png) and audio (mp3, mp4...). It's goot if I can also add other types of media like pdf and so on which are on the picture.
I know how I can add a media element with "assets" in TCA, but then I can't use my variable.
I added two fields in TCA, a filed for media and another one for image. But then I need two variables for them. I want to use just a variable for a field which has medias and images.
This is my field for media now:
$GLOBALS['TCA']['tt_content']['columns'] = array_replace_recursive(
$GLOBALS['TCA']['tt_content']['columns'],
[
'tx_pagesaddfields_slider1_video2' => array(
'exclude' => 1,
'label' => 'Video',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'tx_pagesaddfields_slider1_video2',
array(
'foreign_types' => array(
\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => array(
'showitem' => '
--palette--;;audioOverlayPalette,
--palette--;;filePalette',
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => array(
'showitem' => '
--palette--;;videoOverlayPalette,
--palette--;;filePalette',
)
)
),
'wav,mpeg,mp4,ogg'
)
)
]
);
And this is my field for image now:
$GLOBALS['TCA']['tt_content']['columns'] = array_replace_recursive(
$GLOBALS['TCA']['tt_content']['columns'],
[
'tx_pagesaddfields_slider1_image2' => [
'exclude' => 1,
'label' => 'Image',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'tx_pagesaddfields_slider1_image2',
[
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference'
],
'overrideChildTca' => [
'columns' => [
'crop' => [
'description' => 'field description',
],
],
'types' => [
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
'showitem' => '
--palette--;;imageoverlayPalette,
--palette--;;filePalette'
],
],
],
],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
],
]
);
Like I've already said, I want to add just one field for media & image like this:
I've searched a lot, but I can't find the codes for that.
If you know how you can add a custom field for media&image, please answer here.
Thank you for your help.
CodePudding user response:
Take a look at typo3/sysext/frontend/Configuration/TCA/tt_content.php
'assets' => [
'label' => 'LLL:EXT:frontend/Resources/Private/Language/Database.xlf:tt_content.asset_references',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('assets', [
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/Database.xlf:tt_content.asset_references.addFileReference'
],
// custom configuration for displaying fields in the overlay/reference table
// behaves the same as the image field.
'overrideChildTca' => [
'types' => [
'0' => [
'showitem' => '
--palette--;;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
'showitem' => '
--palette--;;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
'showitem' => '
--palette--;;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => [
'showitem' => '
--palette--;;audioOverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => [
'showitem' => '
--palette--;;videoOverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [
'showitem' => '
--palette--;;imageoverlayPalette,
--palette--;;filePalette'
]
],
],
], $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext'])
],