我尝试将 FileUpload 添加到扩展词汇表 2 中。它适用于一个文件,但不会创建显示所有输入文件的数组。
打字错误3 11.5.19 词汇表2 5.0.9
TCA/覆盖中的代码
'download' => [
'exclude' => true,
'label' => 'LLL:EXT:sm_glossary/Resources/Private/Language/locallang_db.xlf:tx_smglossary_domain_model_glossary.download',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('download', [
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:media.addFileReference',
'elementBrowserEnabled' => 1,
"enabledControls" => [
"delete" => 1,
"dragdrop" => 1,
"hide" => 1,
"info" => 1,
"localize" => 1,
"sort" => 0
],
"fileUploadAllowed" => 1,
"useSortable" => 1
],
'type' => 'inline',
'foreign_table' => 'sys_file_reference',
'foreign_field' => 'uid_foreign',
'foreign_sortby' => 'sorting_foreign',
'foreign_table_field' => 'tablenames',
'foreign_match_fields' => [
'fieldname' => 'download',
],
'foreign_label' => 'uid_local',
'foreign_selector' => 'uid_local',
'maxitems' => 5,
]
),
],
域名/型号/
<?php
declare(strict_types=1);
namespace SM\SmGlossary\Domain\Model;
/**
* Glossary
*/
class Glossary extends \JWeiland\Glossary2\Domain\Model\Glossary
{
/**
* Download
*
* @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
* @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")
*/
protected $download = null;
/**
* Returns the download
*
* @return \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
public function getDownload()
{
return $this->download;
}
/**
* Sets the download
*
* @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $download
* @return void
*/
public function setDownload(\TYPO3\CMS\Extbase\Domain\Model\FileReference $download)
{
$this->download = $download;
}
}
我可以在后端插入多个文件,但在前端 f:debug 只显示一个:
SM\SmGlossary\Domain\Model\Glossary prototype persistent entity (uid=17, pid=147)
download => protected TYPO3\CMS\Extbase\Domain\Model\FileReferenceprototypepersistent entity (uid=41, pid=147)
uidLocal => protected 138 (integer)
originalResource => protected NULL
uid => protected41 (integer)
_localizedUid => protected 41 (integer) modified
_languageUid => protected 0 (integer) modified
_versionedUid => protected 41 (integer) modified
pid => protected 147 (integer)
我在TCA中尝试了不同的设置,但没有达到预期的成功
问题出在你的模型上。当您想要获取多个文件时,您需要使用 ObjectStorage。
喜欢:
<?php
declare(strict_types=1);
namespace SM\SmGlossary\Domain\Model;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
/**
* Glossary
*/
class Glossary extends \JWeiland\Glossary2\Domain\Model\Glossary
{
/**
* Download
*
* @var ObjectStorage<FileReference>
* @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")
*/
protected $download = null;
/**
* Returns the download
*
* @return ObjectStorage<FileReference>
*/
public function getDownload()
{
return $this->download;
}
/**
* Sets the download
*
* @param ObjectStorage<FileReference> $download
* @return void
*/
public function setDownload(ObjectStorage $download)
{
$this->download = $download;
}
}
如果你想在某个地方实例化你的模型,那么你还需要添加一个构造函数来实例化你的ObjectStorage
$download
:
public function __construct()
{
$this->download = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectStorage::class);
}
不确定您是否已解决此问题。如果没有,请尝试按如下方式更新您的 TCA:
'download' => [
......
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('download', [
......
'foreign_match_fields' => [
'tablenames' => 'tx_smglossary_domain_model_glossary',
'table_local' => 'sys_file',
],
......
]
),
......
],