0
votes

I am confused because I figured out, that there are 2 different FileReference classes inside TYPO3. One of them is from the Core and the other one is from Extbase.

The one from the core has function like delete(), but this delete is not implemented yet. I cannot find any function for deleting the FileReference.

If I use update in my extension from the repository, the image will be added not replaced by the new one.

I would like to understand how I can add, delete and fetch files to/from ext_file_reference in a simple way.

Does anybody have a solution or a hint?

2

2 Answers

0
votes

It's unclear from your question what you are trying to do.

If you want to replaces files, you do that on the File Object itself, not the references. But note, that this replaces the file for all references. There is a replaceFile() function on the ResourceStorage object of the file.

If you want to replace a file in a Property, you have to detach one file and attach the other. Every Property that holds FileReferences is an ObjectStorage, and as such comes with attach() and detach() methods to do that.

0
votes

let me try to explain it in more details.
I try to replace an image on a page with another one, but without modifying the image at all. Also the new image is already stored under fileadmin. I would need a new filereference and to replace the old one in the sys_file_reference. So attach and detach would be the goodsolutions, but are not working with extbase filereference. For that I need a \TYPO3\CMS\Extbase\Persistence\ObjectStorage object. I tried "\TYPO3\CMS\Extbase\Persistence\ObjectStorage<\HGA\Hgarecipes\Domain\Model\FileReference>" but it creates an error "Cannot cast object of type "TYPO3\CMS\Extbase\Persistence\ObjectStorage" to string". So finally I am looking for a sulution to add and delete images from sys_file_reference under extbase. I found many pleople which are looking for something, but no solution. Alo if I use the objectstorage I have not longer access to the originalResource of the filereference.

With other words, to create a entry in the sys_file_reference with a given filepath and delete this entry if not longer needed.

On the other hand I want to understand why extbase needs a own filereference.