#66813Persisting extbase FileReference does not work with default TCA configuration
Description
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: https://github.com/helhum/upload_example/blob/master/Configuration/TCA/tx_uploadexample_domain_model_example.php#L136
Is this intended? If it is, why doesn’t getFileFieldTCAConfig do it like this by default?
Reviews 1
Related issues 2
History 819
-
Wouter Wolters commented and changed status
NewClosed <span data-processor="relativetime" data-value="2015-05-06T18:45:14+00:00" > 05/06/15, 18:45 </span> -
Helmut Hummel commented and changed status
ClosedAccepted Complexity hard <span data-processor="relativetime" data-value="2015-05-07T11:47:36+00:00" > 05/07/15, 11:47 </span>This is an inconsistency, which is worth tackling. However, I’m not sure
yet whether we should do son in the TCA helper method or in Extbase
peristence …I
-
Philipp Kerling commented <span data-processor="relativetime" data-value="2015-05-10T09:48:11+00:00" > 05/10/15, 09:48 </span>
I’ve noticed that at least ‘tablenames’ does seem to get set when the domain model uses an ObjetStorage for multiple FAL references. ‘table_local’ is still empty.
So I’d say fix it in Extbase, since the TCA should be OK the way it is.- ‘tablenames’ can be inferred from TCA ‘foreign_table_field’ which is correctly set. This needs to get fixed in Extbase when persisting properties that are a single FileReference (those properties currently have some other problems, but I’ll file separate bug reports for that)
- ‘table_local’ should (always) be set to ‘sys_file’ because that is the default value for the column given in the ‘sys_file_reference’ TCA.
-
Susanne Moog changed category <span data-processor="relativetime" data-value="2018-01-24T20:02:51+00:00" > 01/24/18, 20:02 </span>
-
Christian Eßl changed Related to #88833 <span data-processor="relativetime" data-value="2019-09-24T18:49:44+00:00" > 09/24/19, 18:49 </span>
-
Christian Eßl changed Related to #90374 <span data-processor="relativetime" data-value="2020-02-16T13:23:55+00:00" > 02/16/20, 13:23 </span>
-
Gerrit Code Review pushed patch set 1 for main to change 78166 status
AcceptedUnder Review <span data-processor="relativetime" data-value="2023-03-17T23:40:40+00:00" > 03/17/23, 23:40 </span> -
Gerrit Code Review pushed patch set 2 for main to change 78166 <span data-processor="relativetime" data-value="2023-03-17T23:52:52+00:00" > 03/17/23, 23:52 </span>
-
Stefan Froemken commented and changed status
Under ReviewClosed assigned to Stefan Froemken <span data-processor="relativetime" data-value="2023-06-26T10:12:22+00:00" > 06/26/23, 10:12 </span>Hello Philipp,
thank you for providing this issue to us.
Here are some annotations regarding your ticket:
I have just tried to test that issue in TYPO3 12.4.2 and can not reproduce it anymore.- Setting uid_foreign AND uid_to a random value is not the way to go
- getFileFieldTCAConfig is replaced by type = ‘file’
- tablename will be set automatically now
- table_local has been removed
IMO this problem is solved now.
I will close the ticket now. If you feel this is the wrong decision, let me know, and I will re-open it.
Stefan
-
Gerrit Code Review pushed patch set 3 for main to change 78166 status
ClosedUnder Review <span data-processor="relativetime" data-value="2024-07-14T21:14:58+00:00" > 07/14/24, 21:14 </span> -
Gerrit Code Review pushed patch set 4 for main to change 78166 <span data-processor="relativetime" data-value="2024-07-14T21:17:14+00:00" > 07/14/24, 21:17 </span>
-
Gerrit Code Review pushed patch set 5 for main to change 78166 <span data-processor="relativetime" data-value="2024-07-15T12:20:25+00:00" > 07/15/24, 12:20 </span>
-
Gerrit Code Review pushed patch set 6 for main to change 78166 <span data-processor="relativetime" data-value="2024-07-15T12:22:45+00:00" > 07/15/24, 12:22 </span>
-
Gerrit Code Review pushed patch set 7 for main to change 78166 <span data-processor="relativetime" data-value="2024-07-15T16:02:19+00:00" > 07/15/24, 16:02 </span>
-
Gerrit Code Review pushed patch set 8 for main to change 78166 <span data-processor="relativetime" data-value="2024-10-18T13:38:17+00:00" > 10/18/24, 13:38 </span>
-
Gerrit Code Review pushed patch set 9 for main to change 78166 <span data-processor="relativetime" data-value="2025-03-19T15:08:49+00:00" > 03/19/25, 15:08 </span>
-
Gerrit Code Review pushed patch set 10 for main to change 78166 <span data-processor="relativetime" data-value="2025-07-07T14:19:48+00:00" > 07/07/25, 14:19 </span>
-
Gerrit Code Review pushed patch set 11 for main to change 78166 <span data-processor="relativetime" data-value="2025-09-29T20:05:09+00:00" > 09/29/25, 20:05 </span>
-
Garvin Hicking changed status
Under ReviewClosed <span data-processor="relativetime" data-value="2026-02-27T09:47:54+00:00" > 02/27/26, 09:47 </span>
Hi Philipp,
This not the right place to ask questions. This a bugtracker. Please use the Mailinglist/Forum for questions.
Forum can be found at https://forum.typo3.org/
I will close this ticket to keep the bugtracker clean.