TYPO3 6.2 - Wie erstelle ich FileReference im Frontend (FE)?
Ich habe die hypothetischeZoo
Nebenstelle in der ich @ haAnimal
Modell mitphoto
field und FrontEnd (FE) Plugin mit typischen CRUD-Aktionen.photo
Feld ist typisch für FAL'sFileReference
und es funktioniert perfekt im Backend (BE) mit der üblichen TCA IRRE-Konfiguration.
Ich kann die Datei erfolgreich in den Speicher hochladen. Sie wird im @ angezeig Dateiliste -Modul, und ich kann es in BE während meiner Tierbearbeitung verwenden, trotzdem kann ich nicht erstellenFileReference
in meinem FE-Plugin.
ein aktueller Ansatz sieht folgendermaßen aus:
/**
* @param \Zoo\Zoo\Domain\Model\Animal $animal
*/
public function updateAction(\Zoo\Zoo\Domain\Model\Animal $animal) {
// It reads proper uploaded `photo` from form's $_FILES
$file = $this->getFromFILES('tx_zoo_animal', 'photo');
if ($file && is_array($file) && $file['error'] == 0) {
/** @type $storageRepository \TYPO3\CMS\Core\Resource\StorageRepository */
$storageRepository = GeneralUtility::makeInstance('\TYPO3\CMS\Core\Resource\StorageRepository');
$storage = $storageRepository->findByUid(5); // TODO: make target storage configurable
// This adds uploaded file to the storage perfectly
$fileObject = $storage->addFile($file['tmp_name'], $storage->getRootLevelFolder(), $file['name']);
// Here I stuck... below line doesn't work (throws Exception no. 1 :/)
// It's 'cause $fileObject is type of FileInterface and FileReference is required
$animal->addPhoto($fileObject);
}
$this->animalRepository->update($animal);
$this->redirect('list');
}
jeder Versuch, eine Referenz durch diese Zeile zu erstellen, löst eine Ausnahme aus:
$animal->addPhoto($fileObject);
Wie kann ich das beheben?
Checked:DataHandler
Ansatz Verknüpfun) funktioniert auch nicht, da es für FE-Benutzer nicht verfügbar ist.
TL; DR
Wie man hinzufügenFileReference
zuAnimal
Modell aus vorhandenem (gerade erstellten) FAL-Datensatz?