[TYPO3-mvc] Persisting extbase FileReference does not work with default TCA configuration
Philipp Kerling
pkerling at casix.org
Wed May 6 19:06:25 CEST 2015
I try to programatically create a sys_file_reference in a field of a custom domain object in an extbase FE plugin.
This is the code I use:
/* @var $coverImage \TYPO3\CMS\Extbase\Domain\Model\FileReference */
$coverImage = $this->objectManager->get('TYPO3\CMS\Extbase\Domain\Model\FileReference');
$imageReference = $this->resourceFactory->createFileReferenceObject(array(
'uid_local' => $imageFile->getUid(),
'uid_foreign' => \uniqid('NEW_'),
'uid' => \uniqid('NEW_')
));
$coverImage->setOriginalResource($imageReference);
$object->setCoverImage($coverImage);
Sadly, this does not work, as the fields "tablenames" and "table_local" in the sys_file_reference will be empty.
The cover_image field is defined in the TCA as follows:
'cover_image' => array(
'exclude' => 1,
'label' => 'LLL:EXT:openimmo_import/Resources/Private/Language/locallang_db.xlf:tx_openimmoimport_domain_model_realestateobject.cover_image',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'coverImage',
array(
'maxitems' => 1
),
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
),
As you can see, it uses the standard recommended function getFileFieldTCAConfig to generate the field definition.
Now it does work if you add "tablenames" and "table_local" to "foreign_match_fields", like this:
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'coverImage',
array(
'maxitems' => 1,
'foreign_match_fields' => array(
'tablenames' => 'tx_openimmoimport_domain_model_realestateobject',
'table_local' => 'sys_file'
)
),
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
This is also how the upload_example extension does it.
Is this intended? If it is, why doesn't getFileFieldTCAConfig do it like this by default?
(This was originally issue #66813 - I think it might be a bug anyway but I'll try to get confirmation here first)
More information about the TYPO3-project-typo3v4mvc
mailing list