简体   繁体   English

Typo3 7.2将文件引用添加到扩展模型

[英]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: 我正在使用Typo 7.2,正在寻找以下问题的答案:

How to add a generated File as FileReference programmatically to an extension model? 如何以编程方式将生成的文件作为FileReference添加到扩展模型?

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. 完成命令控制器在文件夹上运行,查找特定图像,然后通过GraphicFunctions创建模糊文件。 The generated file is added to the storage as a standalone simple file and appears in the sys_file table. 生成的文件作为独立的简单文件添加到存储,并显示在sys_file表中。

$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: 因此,我成功扩展了FileReference类:

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. 更新将来自Frans的数据集成到ext_typoscript_setup.txt中后,可以保存模型,创建sys_file_reference条目,并且在后端运行良好。 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. sys_file_reference表不包含table_local的值,而后端用户生成的所有条目都将sys_file作为值。
  2. The same applies to l10n_diffsource which holds some binary large object. 持有一些二进制大对象的l10n_diffsource也是如此。 This entry gets inserted in the sys_file_reference table after saving the record manually via backend. 通过后端手动保存记录后,该条目将插入sys_file_reference表中。
  3. The pid of the file_reference has to be set via setPid($model->getPid()), is that okay? 必须通过setPid($ model-> getPid())设置file_reference的pid,可以吗?
  4. The cruser_id is always set to zero. cruser_id始终设置为零。 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. 这不适用于以编程方式添加的fileReference。 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. 当我手动在sys_file_reference表中输入“ sys_file”值时,它们就会列出。
  6. As Helmut Hummels example holds additional data, I'm wondering, if I just miss some stuff. 由于Helmut Hummels的示例包含其他数据,我想知道我是否会错过一些东西。
  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. 该文件引用用于对象存储内部,但由于addImage函数仅调用objectStorage-> attach,我认为这应该可以,并且不需要任何其他objectStorage操作。 Correct? 正确?

You have to tell the extbase persistence layer to use the correct table. 您必须告诉extbase持久层使用正确的表。 See for instance this example https://github.com/helhum/upload_example/blob/master/ext_typoscript_setup.txt 例如参见以下示例https://github.com/helhum/upload_example/blob/master/ext_typoscript_setup.txt

gr. 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. 尝试回答1)参见https://github.com/helhum/upload_example/blob/master/Configuration/TCA/tx_uploadexample_domain_model_example.php#L128您可能应该检查posterWebBlur字段的TCA定义。 Second param of getFileFieldTCAConfig() TT getFileFieldTCAConfig()TT的第二个参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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