[TYPO3-dev] File reference using Extbase/Fluid/FAL and backwards compatibility
Frans Saris
franssaris at gmail.com
Tue Nov 12 22:27:49 CET 2013
Hi Dennis,
/**
* Returns the image1
*
* @return \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
public function getImage1() {
return $this->image1;
}
Should be enough.
And then in fluid
<f:image src="{object.image1.uid}" width="200" treatIdAsReference="1"/>
Maybe you can use this working example as reference. Are multiple
references instead of one.
https://github.com/fsaris/newsfal
Gr. Frans
Op 12 nov. 2013 22:00 schreef "Dennis Luemkemann" <dennis.luemkemann at gmx.de
>:
> Hello Frans,
>
> thanks for your answer.
>
> > Can you post the code of your model here? Looks like you got something
> wrong there?
>
> <?php
> namespace TYPO3\DlCsbesucher\Domain\Model;
>
> class Visit extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
>
> /**
> * The logo
> *
> * @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
> * @lazy
> */
> protected $image1;
>
> /**
> * Returns the image1
> *
> * @return \TYPO3\CMS\Extbase\Domain\Model\FileReference
> */
> public function getImage1() {
> if (!is_object($this->image1)){
> return null;
> } elseif ($this->image1 instanceof
> \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
> $this->image1->_loadRealInstance();
> }
> return $this->image1->getOriginalResource();
> }
>
> /**
> * Sets the image1
> *
> * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $image1
> * @return void
> */
> public function setImage1($image1) {
> $this->image1 = $image1;
> }
>
> /** other simple properties skipped... */
> }
> ?>
>
> > If you do a <f:debug>{imageProperty}</f:debug> shows it a string/int or
> a object.
>
> it shows a FileReference object, the correct one from sys_file_reference,
> which contains the uid_local to the desired image in sys_file:
>
> TYPO3\CMS\Core\Resource\FileReference prototype object
> propertiesOfFileReference => array(32 items)
> uidOfFileReference => NULL
> name => NULL
> fileRepository => TYPO3\CMS\Core\Resource\FileRepository singleton
> object
> objectType => 'TYPO3\CMS\Core\Resource\File' (28 chars)
> table => 'sys_file' (8 chars)
> indexerService => NULL
> factory => TYPO3\CMS\Core\Resource\ResourceFactory singleton object
> storageInstances => array(2 items)
> collectionInstances => array(empty)
> fileInstances => array(2 items)
> 319 => TYPO3\CMS\Core\Resource\File prototype object
> indexed => TRUE
> indexable => TRUE
> metaDataProperties => array(25 items)
> indexingInProgress => FALSE
> updatedProperties => array(empty)
> properties => array(13 items)
> storage => TYPO3\CMS\Core\Resource\ResourceStorage
> prototype object see above
> identifier =>
> '/furniture/willkommen/Flaggen/saudi_arabien.gif' (47 chars)
> name => 'saudi_arabien.gif' (17 chars)
> deleted => FALSE
> 6 => TYPO3\CMS\Core\Resource\File prototype object
> indexed => TRUE
> indexable => TRUE
> metaDataProperties => array(25 items)
> indexingInProgress => FALSE
> updatedProperties => array(empty)
> properties => array(13 items)
> storage => TYPO3\CMS\Core\Resource\ResourceStorage
> prototype object see above
> identifier => '/typo3/sysext/beuser/ext_icon.gif' (33 chars)
> name => 'ext_icon.gif' (12 chars)
> deleted => FALSE
> fileReferenceInstances => array(1 item)
> 6 => TYPO3\CMS\Core\Resource\FileReference prototype object
> see above
> localDriverStorageCache => NULL
> signalSlotDispatcher => TYPO3\CMS\Extbase\SignalSlot\Dispatcher
> singleton object see above
> typeField => '' (0 chars)
> type => '' (0 chars)
> originalFile => TYPO3\CMS\Core\Resource\File prototype object see above
> mergedProperties => array(empty)
>
> I'm surprised that there are two fileInstances: 319 is the uid to the
> correct file in sys_file, but 6 is only the uid of the entry in
> sys_file_reference. In the output I'm getting the image with uid 6 shown.
>
> In the template, I'm using
> <f:image src="{visit.image1.uid}" alt="logo" />
>
> Best regards
> Dennis
>
>
> >> I started writing an extension using Extbase/Fluid on my 6.2 test
> >> installation. I'm using a reference to an image in my model. After
> >> initially building my ext with extension_builder (with type "Image*"
> >> instead of "File reference*" for the image property), I then manually
> >> changed the code following the instructions in the Typo3 Wiki (
> >>
> http://wiki.typo3.org/File_Abstraction_Layer#Usage_in_Extbase_.28in_progress.29
> )
> >> to get image relation in FAL working.
> >>
> >> Result: In the backend I can associate an image, the sys_file_reference
> >> table gets updated properly, BUT in my tx…domain_model_myclass table,
> the
> >> value for the image is always 1 and when I render the image in the fluid
> >> template, I get image uid 1 shown, not my image, which is referenced in
> the
> >> sys_file_reference table. I'm wondering: Did I miss something or has
> >> something changed in 6.2 since the Wiki page was written?
> >>
> >> Also, there seem to be two different ways now for referencing and
> >> rendering images in the legacy file management system and FAL. Can I
> write
> >> one extension that will work on 4.5 LTS and 6.2 LTS or do I have to
> write
> >> two separate exts?
> >>
> >> Thanks
> >> Dennis
> _______________________________________________
> TYPO3-dev mailing list
> TYPO3-dev at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-dev
>
More information about the TYPO3-dev
mailing list