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

After saving $content the image is available through the record and the filemount but the Ref column in BE > FILE > File List) is - and not >= 1. So its look like the reference is some how broken. When I'm using the BE to add an image to the record it's all fine. I'm using TYPO3 CMS 7.3-dev.

What's wrong with my code?

witrin
  • 3,701
  • 1
  • 24
  • 49

2 Answers2

2

I get the hint in the Slack channel of TYPO3.

You just need to set plugin.tx_myext.persistence.updateReferenceIndex = 1 respectively module.tx_myext.persistence.updateReferenceIndex = 1 and the index will be updated.

Alternatively you could use \TYPO3\CMS\Core\Database\ReferenceIndex::updateRefIndexTable().

witrin
  • 3,701
  • 1
  • 24
  • 49
-1

When I had to use FAL in my extension I found this link: http://t3-developer.com/extbase-fluid/extensions-erweitern/fal-in-eigenen-extensions/fal-in-typo3-extensions-verwenden/

Since it is in German, I will in the very shortest explain what is done there:

  1. extend your data model in ext_tables.sql add a column of some char type (e.g. varchar)

  2. add your column to the column section in your TCA array in ext_tables.php

    'mypictures' => array( 'exclude' => 1, 'label' => 'My Pictures', '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']), ),

  3. Extend your modelfiles. Pay attention to annotations!

  4. You can use your media in your fluid template

denvercoder
  • 113
  • 9
  • This does not answer the question. I did not ask how to use FAL in Extbase. I asked about how to use it correctly regarding the reference index. Please read the question carefully. – witrin May 27 '15 at 02:29
  • Sorry! Well as I understand it, you would have to annotate the field in your model class file. – denvercoder May 27 '15 at 08:05
  • Something like this: @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference> – denvercoder May 27 '15 at 08:11
  • Nope, see the other answer. What you mention is 1:1 vs. 1:n relationship but this has nothing to do with the questioned problem. ;) – witrin May 27 '15 at 17:36
  • Ok, it seams I misunderstood the question. Sorry, again. – denvercoder May 29 '15 at 06:54