Bug #66813
openPersisting extbase FileReference does not work with default TCA configuration
0%
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?
Updated by Wouter Wolters over 9 years ago
- Status changed from New to Closed
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.
Updated by Helmut Hummel over 9 years ago
- Status changed from Closed to Accepted
- Complexity set to hard
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
Updated by Philipp Kerling over 9 years ago
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.
Updated by Christian Eßl about 5 years ago
- Related to Feature #88833: Extend possibility to create FileReference in frontend with a given File object added
Updated by Christian Eßl almost 5 years ago
- Related to Feature #90374: Add setOriginaFile / setFile setter to TYPO3\CMS\Extbase\Domain\Model\FileReference added
Updated by Gerrit Code Review over 1 year ago
- Status changed from Accepted to Under Review
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/78166
Updated by Gerrit Code Review over 1 year ago
Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/78166
Updated by Stefan Froemken over 1 year ago
- Status changed from Under Review to Closed
- Assignee set to Stefan Froemken
Hello Philipp,
thank you for providing this issue to us.
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
Updated by Gerrit Code Review 4 months ago
- Status changed from Closed to Under Review
Patch set 3 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/78166
Updated by Gerrit Code Review 4 months ago
Patch set 4 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/78166
Updated by Gerrit Code Review 4 months ago
Patch set 5 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/78166
Updated by Gerrit Code Review 4 months ago
Patch set 6 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/78166
Updated by Gerrit Code Review 4 months ago
Patch set 7 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/78166
Updated by Gerrit Code Review about 1 month ago
Patch set 8 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/78166