【问题标题】:Using FAL in Extbase correctly在 Extbase 中正确使用 FAL
【发布时间】:2015-08-05 12:11:30
【问题描述】:

领域模型

class Image extends AbstractContent {

    /**
     * @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
     */
    protected $file;

    /**
     * Gets the image file
     *
     * @return \TYPO3\CMS\Extbase\Domain\Model\FileReference
     */
    public function getFile() {
        return $this->file;
    }

    /**
     * Sets the image file
     *
     * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $file
     * @return void
     */
    public function setFile($file) {
        $this->file = $file;
    }
}

导入服务片段

/**
 * @var \TYPO3\CMS\Core\Resource\ResourceStorage
 */
protected $defaultStorage;

[...]

$this->defaultStorage = ResourceFactory::getInstance()->getDefaultStorage();

[...]

$file = $this->defaultStorage->addFile(
    '/tmp/4711', 
    $this->defaultStorage->getRootLevelFolder(), 
    'foo.jpg', 
    'overrideExistingFile'
);

$falReference = ResourceFactory::getInstance()->createFileReferenceObject(
    array(
        'uid_local' => $file->getUid(),
        'uid_foreign' => uniqid('NEW_'),
        'uid' => uniqid('NEW_'),
    )
);

$reference = GeneralUtility::makeInstance(FileReference::class);
$reference->setOriginalResource($falReference);

$content = GeneralUtility::makeInstance(Image::class);
$content->setFile($reference);

保存$content 后,图像可通过记录和文件挂载获得,但BE > FILE > File List 中的Ref 列是- 而不是>= 1。所以看起来参考文献有些破损。当我使用 BE 将图像添加到记录时,一切都很好。我正在使用 TYPO3 CMS 7.3-dev。

我的代码有什么问题?

【问题讨论】:

    标签: typo3 extbase fal


    【解决方案1】:

    当我不得不在我的扩展中使用 FAL 时,我发现了这个链接: http://t3-developer.com/extbase-fluid/extensions-erweitern/fal-in-eigenen-extensions/fal-in-typo3-extensions-verwenden/

    由于是德语,我将在最短的时间内解释那里做了什么:

    1. 在 ext_tables.sql 中扩展您的数据模型 添加一些 char 类型的列(例如 varchar)

    2. 将您的列添加到 ext_tables.php 中 TCA 数组的列部分

      '我的图片' => 数组( '排除' => 1, '标签' => '我的图片', 'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('image', array( '外观' => 数组( 'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference' ), '小物品' => 0, 'maxitems' => 99, ), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']), ),

    3. 扩展您的模型文件。注意注释!

    4. 您可以在流体模板中使用您的媒体

    【讨论】:

    • 这没有回答问题。我没有问如何在 Extbase 中使用 FAL。我询问了如何正确使用参考索引。请仔细阅读问题。
    • 对不起!好吧,据我了解,您必须在模型类文件中注释该字段。
    • 类似这样的东西:@var \TYPO3\CMS\Extbase\Persistence\ObjectStorage
    • 不,请参阅其他答案。您提到的是 1:1 与 1:n 的关系,但这与所质疑的问题无关。 ;)
    • 好吧,我误解了这个问题。再次抱歉。
    【解决方案2】:

    我在Slack channel of TYPO3 中得到了提示。

    只需分别设置plugin.tx_myext.persistence.updateReferenceIndex = 1module.tx_myext.persistence.updateReferenceIndex = 1,索引就会更新。

    您也可以使用\TYPO3\CMS\Core\Database\ReferenceIndex::updateRefIndexTable()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-02
      相关资源
      最近更新 更多