首页 文章

正确使用Extbase中的FAL

提问于
浏览
1

Domain model

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;
    }
}

Import service fragments

/**
 * @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 后,图像可通过记录和filemount获得,但 BE > FILE > File List 中的 Ref 列是 - 而不是 >= 1 . 所以看起来像参考是有些破碎的 . 当我'm using the BE to add an image to the record it'一切都很好 . 我正在使用TYPO3 CMS 7.3-dev .

我的代码出了什么问题?

2 回答

  • 1

    我在Slack channel of TYPO3得到了提示 .

    您只需要分别设置 plugin.tx_myext.persistence.updateReferenceIndex = 1 module.tx_myext.persistence.updateReferenceIndex = 1 ,即可更新索引 .

    或者你可以使用 \TYPO3\CMS\Core\Database\ReferenceIndex::updateRefIndexTable() .

  • -1

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

    既然是德语,我会在最短的时候解释那里做了什么:

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

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

    'mypictures'=> array('exclude'=> 1,'label'=>'我的图片','config'=> \ TYPO3 \ CMS \ Core \ Utility \ ExtensionManagementUtility :: getFileFieldTCAConfig('image',array(' appearance'=> array('createNewRelationLinkTitle'=>'LLL:EXT:cms / locallang_ttc.xlf:images.addFileReference'),'minitems'=> 0,'maxitems'=> 99,),$ GLOBALS ['TYPO3_CONF_VARS' ] ['GFX'] ['imagefile_ext']),),

    • 扩展您的模板文件 . 注意注释!

    • 您可以在流体模板中使用媒体

相关问题