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

Also available in: Atom PDF