Issue Feature Closed

#90374Add setOriginaFile / setFile setter to TYPO3\CMS\Extbase\Domain\Model\FileReference

This Mächler 02/15/20, 02:52 updated 07/15/24, 12:22

Description

Creating a new file reference in frontend context is not properly possible right now.

I read this tutorial that describes the issue:
https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Fal/UsingFal/ExamplesFileFolder.html?highlight=file%20reference#in-the-frontend-context

And studied this example:
“A cleaner solution using Extbase requires far more work. An example can be found here: https://github.com/helhum/upload_example”

The problem is, that this approach is not clean. resourceFactory->createFileReferenceObject creates a dead useless sys_file_reference – record in the database (with just a relation to the file, but not to any foreign table record) each time a new file-reference is created. This is only necessary to provide a ‘originalResource’ to the TYPO3\CMS\Extbase\Domain\Model\FileReference, which does noting else than fetching the original file from the useless ghos-file-reference:

   public function setOriginalResource(\TYPO3\CMS\Core\Resource\ResourceInterface $originalResource)
     {
         $this->originalResource = $originalResource;
         $this->uidLocal = (int)$originalResource->getOriginalFile()->getUid();
     }

This could be avoided by just adding a public function to set the file directly to the reference (which makes a lot of sense?):

   public function setOriginalFile(\TYPO3\CMS\Core\Resource\File $originalFile)
     {
         $this->uidLocal = (int)$originalFile->getUid();
     }

Just now you have to create your own class derived from TYPO3\CMS\Extbase\Domain\Model\FileReference and add this setter to avoid creating a dead record.

Second problem comes on persisting the file reference by the exbase framework, the created record does have an empty ‘table_local’ field, which leads to improper handling of the reference in the backend, see here: https://forge.typo3.org/issues/90373

Would be nice to have this fixed, making FAL work properly with extbase!

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.