I would like to add additional metadata (e.g. copyright) to an image in tt_content (the standard IRRE field in TYPO3 8.7).
I intalled the "filemetadata" extension to get these additional fields. If I open a sys_file_reference, I have access to the fields. Now I want to show the copyright field to the tt_content IRRE "image" field, which is currently showing the standard fields"title,description,link".
I tried to override the TCA (myExtension/Configuration/TCA/Override/tt_content.php):
'image' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.images',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('image', [
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference'
],
// custom configuration for displaying fields in the overlay/reference table
// to use the imageoverlayPalette instead of the basicoverlayPalette
'overrideChildTca' => [
'types' => [
'0' => [
'showitem' => 'copyright,
--palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
'showitem' => '
--palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
'showitem' => '
--palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
copyright,--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => [
'showitem' => '
--palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.audioOverlayPalette;audioOverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => [
'showitem' => '
--palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.videoOverlayPalette;videoOverlayPalette,
--palette--;;filePalette'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [
'showitem' => '
--palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
]
],
],
], $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
],
and like this in the localconf of myExtension:
$GLOBALS['TCA']['sys_file_reference']['types'] =[
'0' => array('showitem' => 'uid_local,uid_foreign,tablenames,fieldname,title,description,copyright'),
];
but the copyright field will not appear. Please help.
I found a dirty solution. The main Problem is, that sys_file_metadata is not related to sys_file_reference!
I fixed my problem:
EXT:myext/Configuration/TCA/Overrides/sys_file_reference.php:
$metaDataSysFileReferenceColumns = [
'metadata' => array (
'exclude' => 1,
'label' => 'Metadata',
'config' => array (
'type' => 'user',
'userFunc' => \VENDOR\MyExt\UserFunction\ProviderField::class . '->getMetaData',
)
)]; \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file_reference', $metaDataSysFileReferenceColumns); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette('sys_file_reference', 'metaPalette', 'metadata');
Userfunction ProviderField->getMetaData() public function getMetaData(array $parameters, $parentObject) {
$uid = $parameters['row']['uid_local'][0]['uid'];
$sys_language_uid = 0;
if (!empty($parameters['row']['sys_language_uid'])) {
$sys_language_uid = $parameters['row']['sys_language_uid'][0];
}
$queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
->getQueryBuilderForTable('sys_file_metadata');
$recordInDatabase = $queryBuilder
->select('*')
->from('sys_file_metadata')
->where(
$queryBuilder->expr()->eq(
'file',
$queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
),
$queryBuilder->expr()->eq(
'sys_language_uid',
$queryBuilder->createNamedParameter($sys_language_uid, \PDO::PARAM_INT)
)
)
->setMaxResults(1)
->execute()
->fetch();
$html = array();
$html[] = '
<div class="row">
<div class="form-group t3js-formengine-validation-marker t3js-formengine-palette-field col-sm-6">
<label class="t3js-formengine-label">
Creator
</label>
<div class="formengine-field-item t3js-formengine-field-item">
<div class="form-control-wrap" style="max-width: 480px">
<div class="form-wizards-wrap">
<div class="form-wizards-element">
<div class="form-control-clearable">
<input type="text" id="formengine-input-'.uniqid().'"
class="form-control t3js-clearable hasDefaultValue"
data-formengine-validation-rules="[{"type":"trim"}]"
data-formengine-input-params="{"field":"data[sys_file_metadata]['.$recordInDatabase['uid'].'][creator]","evalList":"trim","is_in":""}"
data-formengine-input-name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][creator]"
data-formengine-input-initialized="true">
<button type="button" class="close" tabindex="-1" aria-hidden="true" style="display: none;">
<span class="t3js-icon icon icon-size-small icon-state-default icon-actions-close" data-identifier="actions-close">
<span class="icon-markup">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
<path d="M11.9 5.5L9.4 8l2.5 2.5c.2.2.2.5 0 .7l-.7.7c-.2.2-.5.2-.7 0L8 9.4l-2.5 2.5c-.2.2-.5.2-.7 0l-.7-.7c-.2-.2-.2-.5 0-.7L6.6 8 4.1 5.5c-.2-.2-.2-.5 0-.7l.7-.7c.2-.2.5-.2.7 0L8 6.6l2.5-2.5c.2-.2.5-.2.7 0l.7.7c.2.2.2.5 0 .7z" class="icon-color"></path>
</svg>
</span>
</span>
</button>
</div>
<input type="hidden" name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][creator]" value="'.$recordInDatabase['creator'].'">
</div>
<div class="form-wizards-items-aside">
<div class="btn-group"></div>
</div>
<div class="form-wizards-items-bottom"></div>
</div>
</div>
</div>
</div>
<div class="form-group t3js-formengine-validation-marker t3js-formengine-palette-field col-sm-6">
<label class="t3js-formengine-label">
Source
</label>
<div class="formengine-field-item t3js-formengine-field-item">
<div class="form-control-wrap" style="max-width: 480px">
<div class="form-wizards-wrap">
<div class="form-wizards-element">
<div class="form-control-clearable">
<input type="text" id="formengine-input-'.uniqid().'"
class="form-control t3js-clearable hasDefaultValue"
data-formengine-validation-rules="[{"type":"trim"}]"
data-formengine-input-params="{"field":"data[sys_file_metadata]['.$recordInDatabase['uid'].'][source]","evalList":"trim","is_in":""}"
data-formengine-input-name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][source]"
data-formengine-input-initialized="true">
<button type="button" class="close" tabindex="-1" aria-hidden="true" style="display: none;">
<span class="t3js-icon icon icon-size-small icon-state-default icon-actions-close" data-identifier="actions-close">
<span class="icon-markup">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
<path d="M11.9 5.5L9.4 8l2.5 2.5c.2.2.2.5 0 .7l-.7.7c-.2.2-.5.2-.7 0L8 9.4l-2.5 2.5c-.2.2-.5.2-.7 0l-.7-.7c-.2-.2-.2-.5 0-.7L6.6 8 4.1 5.5c-.2-.2-.2-.5 0-.7l.7-.7c.2-.2.5-.2.7 0L8 6.6l2.5-2.5c.2-.2.5-.2.7 0l.7.7c.2.2.2.5 0 .7z" class="icon-color"></path>
</svg>
</span>
</span>
</button>
</div>
<input type="hidden" name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][source]" value="'.$recordInDatabase['source'].'">
</div>
<div class="form-wizards-items-aside">
<div class="btn-group"></div>
</div>
<div class="form-wizards-items-bottom"></div>
</div>
</div>
</div>
</div>
<div class="form-group t3js-formengine-validation-marker t3js-formengine-palette-field col-sm-6">
<label class="t3js-formengine-label">
Copyright
</label>
<div class="formengine-field-item t3js-formengine-field-item">
<div class="form-control-wrap" style="max-width: 480px">
<div class="form-wizards-wrap">
<div class="form-wizards-element">
<div class="form-control-clearable">
<input type="text" id="formengine-input-'.uniqid().'"
class="form-control t3js-clearable hasDefaultValue"
data-formengine-validation-rules="[{"type":"trim"}]"
data-formengine-input-params="{"field":"data[sys_file_metadata]['.$recordInDatabase['uid'].'][copyright]","evalList":"trim","is_in":""}"
data-formengine-input-name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][copyright]"
data-formengine-input-initialized="true">
<button type="button" class="close" tabindex="-1" aria-hidden="true" style="display: none;">
<span class="t3js-icon icon icon-size-small icon-state-default icon-actions-close" data-identifier="actions-close">
<span class="icon-markup">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
<path d="M11.9 5.5L9.4 8l2.5 2.5c.2.2.2.5 0 .7l-.7.7c-.2.2-.5.2-.7 0L8 9.4l-2.5 2.5c-.2.2-.5.2-.7 0l-.7-.7c-.2-.2-.2-.5 0-.7L6.6 8 4.1 5.5c-.2-.2-.2-.5 0-.7l.7-.7c.2-.2.5-.2.7 0L8 6.6l2.5-2.5c.2-.2.5-.2.7 0l.7.7c.2.2.2.5 0 .7z" class="icon-color"></path>
</svg>
</span>
</span>
</button>
</div>
<input type="hidden" name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][copyright]" value="'.$recordInDatabase['copyright'].'">
</div>
<div class="form-wizards-items-aside">
<div class="btn-group"></div>
</div>
<div class="form-wizards-items-bottom"></div>
</div>
</div>
</div>
</div>
<div class="form-group t3js-formengine-validation-marker t3js-formengine-palette-field col-sm-6">
<label class="t3js-formengine-label">
Publisher
</label>
<div class="formengine-field-item t3js-formengine-field-item">
<div class="form-control-wrap" style="max-width: 480px">
<div class="form-wizards-wrap">
<div class="form-wizards-element">
<div class="form-control-clearable">
<input type="text" id="formengine-input-'.uniqid().'"
class="form-control t3js-clearable hasDefaultValue"
data-formengine-validation-rules="[{"type":"trim"}]"
data-formengine-input-params="{"field":"data[sys_file_metadata]['.$recordInDatabase['uid'].'][publisher]","evalList":"trim","is_in":""}"
data-formengine-input-name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][publisher]"
data-formengine-input-initialized="true">
<button type="button" class="close" tabindex="-1" aria-hidden="true" style="display: none;">
<span class="t3js-icon icon icon-size-small icon-state-default icon-actions-close" data-identifier="actions-close">
<span class="icon-markup">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
<path d="M11.9 5.5L9.4 8l2.5 2.5c.2.2.2.5 0 .7l-.7.7c-.2.2-.5.2-.7 0L8 9.4l-2.5 2.5c-.2.2-.5.2-.7 0l-.7-.7c-.2-.2-.2-.5 0-.7L6.6 8 4.1 5.5c-.2-.2-.2-.5 0-.7l.7-.7c.2-.2.5-.2.7 0L8 6.6l2.5-2.5c.2-.2.5-.2.7 0l.7.7c.2.2.2.5 0 .7z" class="icon-color"></path>
</svg>
</span>
</span>
</button>
</div>
<input type="hidden" name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][publisher]" value="'.$recordInDatabase['publisher'].'">
</div>
<div class="form-wizards-items-aside">
<div class="btn-group"></div>
</div>
<div class="form-wizards-items-bottom"></div>
</div>
</div>
</div>
</div>
</div>';
return implode(LF, $html);
}
Last step override the assets (FileReference) in tt_content: EXT:myext/Configuration/TCA/Overrides/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 'overrideChildTca' => [ 'types' => [ '0' => [ 'showitem' => ' --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;metaPalette, --palette--;;imageoverlayPalette, --palette--;;filePalette' ], \TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [ 'showitem' => ' --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;metaPalette, --palette--;;imageoverlayPalette, --palette--;;filePalette' ], \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [ 'showitem' => ' --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;metaPalette, --palette--;;imageoverlayPalette, --palette--;;filePalette' ], \TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => [ 'showitem' => ' --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;metaPalette, --palette--;;imageoverlayPalette, --palette--;;filePalette' ], \TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => [ 'showitem' => ' --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;metaPalette, --palette--;;imageoverlayPalette, --palette--;;filePalette' ], \TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [ 'showitem' => ' --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;newsPalette, --palette--;;imageoverlayPalette, --palette--;;filePalette' ] ], ], ], $GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext']) ],
Voila, each Media Element in tt_content will show the additional metadata infos on collapsing IRRE. I know, it's really dirty...