1

领域模型

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图像可通过记录和文件挂载获得,但 ) 中的RefBE > FILE > File List-和不是>= 1。所以看起来参考文献有些破损。当我使用 BE 将图像添加到记录时,一切都很好。我正在使用 TYPO3 CMS 7.3-dev。

我的代码有什么问题?

4

2 回答 2

2

我在TYPO3 的 Slack 频道中得到了提示。

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

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

于 2015-05-23T18:50:50.990 回答
-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 数组的列部分

    'mypictures' => array('exclude' => 1, 'label' => 'My Pictures', 'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('image', array('外观' => 数组('createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference' ), 'miniitems' => 0, 'maxitems' => 99, ), $GLOBALS['TYPO3_CONF_VARS' ]['GFX']['imagefile_ext']), ),

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

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

于 2015-05-26T21:39:37.457 回答