简体   繁体   中英

Typo3 7.2 add file reference to extension model

I'm using Typo 7.2 and am looking for an answer to the following question:

How to add a generated File as FileReference programmatically to an extension model?

First some infos regarding my achievements/tries.

DONE A command controller runs over folders, looks for a specific image and creates a blurred file via GraphicFunctions. The generated file is added to the storage as a standalone simple file and appears in the sys_file table.

$fileObject = $posterStorage->addFile(
  $convertResult[3],
  $posterStorage->getFolder($blurFolderName),
  $newFileName);

PARTIALLY DONE. Now I need to add the generated file as a file reference to my model. The problem is, that I'm able to do this, but only by hacking core - not acceptable - and unable to do it the right way. The model says:

public function addPosterWebBlur(
\TYPO3\CMS\Extbase\Domain\Model\FileReference $posterWebBlur
) {
  $this->posterWebBlur->attach($posterWebBlur);
}

So I succeeded by extending the FileReference class:

class FileReference extends \TYPO3\CMS\Extbase\Domain\Model\FileReference {
  public function setFile(\TYPO3\CMS\Core\Resource\File $falFile) {
    $this->$uidLocal = (int)$falFile->getUid();
  }
}

The reference does not get established and I just get the following error in the backend:

Table 'db_name.tx_ext_name_domain_model_filereference' doesn't exist.

UPDATE After integrating the data from Frans in ext_typoscript_setup.txt, the model can be saved, creates an sys_file_reference entry and acts nicely in the backend. But there are a few points open to fulfill all needs:

  1. The sys_file_reference table does not contain a value for table_local, whereas all the entries generated by a backend user hold sys_file as value.
  2. The same applies to l10n_diffsource which holds some binary large object. This entry gets inserted in the sys_file_reference table after saving the record manually via backend.
  3. The pid of the file_reference has to be set via setPid($model->getPid()), is that okay?
  4. The cruser_id is always set to zero. Is this the correct way?
  5. When trying to delete a file (which was added to a model with the backend possibilities) via the file manager, I get a warning, that references to this file exist. This does not apply to the fileReference added programmatically. Also the references listed under the file (when clicking on "Info" for a generated file in the backend file manager) don't get listed. They get listed, when I enter the "sys_file" value in the sys_file_reference table by hand.
  6. As Helmut Hummels example holds additional data, I'm wondering, if I just miss some stuff.
  7. The file reference is used inside an object storage, but as the addImage function only calls objectStorage->attach I think this should be okay and no additional objectStorage actions are neccessary. Correct?

You have to tell the extbase persistence layer to use the correct table. See for instance this example https://github.com/helhum/upload_example/blob/master/ext_typoscript_setup.txt

gr. Frans

Trying to answer 1) See https://github.com/helhum/upload_example/blob/master/Configuration/TCA/tx_uploadexample_domain_model_example.php#L128 You should probably check the TCA definition for your posterWebBlur field. Second param of getFileFieldTCAConfig() TT

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM