Project

General

Profile

Actions

Feature #88833

open

Extend possibility to create FileReference in frontend with a given File object

Added by Jan Kornblum over 5 years ago. Updated about 1 month ago.

Status:
Under Review
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2019-07-24
Due date:
% Done:

0%

Estimated time:
PHP Version:
7.3
Tags:
Extbase, FileReference, FAL, Frontend, Create
Complexity:
Sprint Focus:

Description

Related to https://forge.typo3.org/issues/48965#note-21 it is still not possible, to create a FileReference in frontend context by a given File object. So still a custom extended FileReference class is neccessary. Please add a setFile() method to the native Extbase FileReference class like this:

/**
 * Class FileReference
 */
class FileReference extends \TYPO3\CMS\Extbase\Domain\Model\FileReference {

    /**
     * uid of a sys_file
     *
     * @var integer
     */
    protected $originalFileIdentifier;

    /**
     * setOriginalResource
     *
     * @param \TYPO3\CMS\Core\Resource\ResourceInterface $originalResource
     * @return void
     */
    public function setOriginalResource(\TYPO3\CMS\Core\Resource\ResourceInterface $originalResource) {
        $this->originalResource = $originalResource;
        $this->originalFileIdentifier = (int)$originalResource->getOriginalFile()->getUid();
    }

    /**
     * setFile
     *
     * @param \TYPO3\CMS\Core\Resource\File $falFile
     * @return void
     */
    public function setFile(\TYPO3\CMS\Core\Resource\File $falFile) {
        $this->originalFileIdentifier = (int)$falFile->getUid();
    }

}

With this, creating a new FileReference in frontend will be possible by core for all three variants like following:

// A) File Objekt already exists in Storage(but Storage doesn't know it yet):
$file = ResourceFactory::getInstance()->retrieveFileOrFolderObject('path_to_file');

// B) File Objekt exists anywhere and will be copied to storage:
$storage = ResourceFactory::getInstance()->getDefaultStorage();
$file = $storage->getFolder('folder_name')->addFile('path_to_file');

// C) File Objekt doesn't yet existan will be created as an empty file (can be filled later using setContents() or else):
$storage = ResourceFactory::getInstance()->getDefaultStorage();
$file = $storage->getFolder('folder_name')->createFile('path_to_file', $folder);

// Create the file reference itself here (for A, B, and C)
$fileReference = $objectManager->get(\TYPO3\CMS\Extbase\Domain\Model\FileReference::class);
$fileReference->setFile($file);  

Related issues 3 (1 open2 closed)

Related to TYPO3 Core - Bug #66813: Persisting extbase FileReference does not work with default TCA configurationUnder ReviewStefan Froemken2015-05-06

Actions
Related to TYPO3 Core - Feature #90374: Add setOriginaFile / setFile setter to TYPO3\CMS\Extbase\Domain\Model\FileReferenceClosed2020-02-15

Actions
Related to TYPO3 Core - Bug #48965: FileReference can't be created in Frontend contextClosed2013-06-08

Actions
Actions #1

Updated by Christian Eßl about 5 years ago

  • Related to Bug #66813: Persisting extbase FileReference does not work with default TCA configuration added
Actions #2

Updated by Yohann CERDAN almost 5 years ago

+1 for this, i dont know why this is not by default after such a time.

Actions #3

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
Actions #4

Updated by Jan Kornblum about 4 years ago

  • Related to Bug #48965: FileReference can't be created in Frontend context added
Actions #5

Updated by Jan Kornblum about 4 years ago

  • Category changed from File Abstraction Layer (FAL) to Extbase

Nobody interested in improving this? Since FAL has already been introduced in 6 LTS (?) there is still no native support for such basic tasks? I'm sorry if this is not as simple as it seems to me (i am not a core developer)...

If anybody will implement this missing feature, please also respect this (https://forge.typo3.org/issues/66813#note-3) related issue, to prevent the need to extend the TCA's "foreign_match_fields" always.

Actions #6

Updated by Stefan Neufeind over 3 years ago

Stumbled across this again. We really should find a way to easily create a filereference - either by using a file-object and being able to create a filereference from there or like described here by creating a new reference and assigning it a file.

Use-case is for example: You have a FrontendUser-object, have an image in the filesystem (and can easily request a file-object for it) ... and need to call FrontendUser::setImage() with an ObjectStorage holding a file-reference.
Maybe we could also allow to pass a file-object there and setImage would itself create the needed FileReference out of it.

Blogpost (in German) refering to this issue here:
https://www.typo3tiger.de/blog/post/extbase-fal-filereference-erzeugen-update.html

Actions #7

Updated by Jan Kornblum over 1 year ago

Update dead link "Blogpost (in German) refering to this issue here":

https://buergel.dev/blog/post/extbase-fal-filereference-erzeugen-update.html

Actions #8

Updated by Gerrit Code Review over 1 year ago

  • Status changed from New to Under Review

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

Actions #9

Updated by JAKOTA Design Group GmbH over 1 year ago

As requested, I looked into this issue and it seems that only the file setter is missing.

But I have to test this with a real project, which I haven't done yet.

So please go ahead, if you have some time on your hand, and try this yourself.

Actions #10

Updated by Gerrit Code Review 4 months ago

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

Actions #11

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

Actions #12

Updated by Jan Kornblum 4 months ago · Edited

I've adjusted this for current master and tested it in a real project.

Actions #13

Updated by JAKOTA Design Group GmbH 4 months ago

Thanks for the update. I've also tested this in one of my projects. And it works as expected.

lets see what the what the devs have to say about it.
this could be seen as a bugfix or new feature and depending on this classification more work needs to be done.

Actions #14

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

Actions #15

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

Actions #16

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

Actions #17

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

Actions

Also available in: Atom PDF