[TYPO3-dev] FAL in an Extbase 6.0 extension... but how?!
    Helmut Hummel 
    helmut.hummel at typo3.org
       
    Wed Feb  6 18:21:22 CET 2013
    
    
  
Hi,
On 31.01.13 18:37, Anders Gissel wrote:
> thanks to some helpful tips from a fellow TYPO3-freak, I was able to get
> things up and running.
Great you managed to get it going. Who was the "TYPO3-freak"? :)
> Mind you, these are extremely dirty hacks (albeit
> inside your own extension only),
It is not that bad, if you skip the select query and use an API method 
for that as I will show below.
> and once Extbase starts properly
> supporting FAL (which, currently, it doesn't), you will have to change a
> lot of things, at the very least in your frontend rendering.
We will be working on that during the Extbase code sprint this weekend.
> You'd be
> wise to plan accordingly. But without further ado, here's how to use FAL
> to attach a single image to a domain model object, and then retrieve the
> raw data in frontend.
You could use the object instead. Works fine with all the getters that 
do not have parameters (like getProperty).
> Here's where things get tricky. Your regular domain model should
> probably look something like this:
>       /**
>        * Returns the file USING HAXX0RED METHODS! PLEASE DON'T TRY THIS
> AT HOME, KIDS!
:)
>        *
>        * @return array $file
>        */
>       public function getFile() {
>
>           // Get the UID from the current image object.
>           $objectUid = $this->getUid();
>
>           // Use the UID to search sys_file_reference
>           $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('uid',
> 'sys_file_reference', "uid_foreign={$objectUid} AND fieldname = 'file'
> AND tablenames = 'tx_myext_domain_model_image' AND deleted=0 AND hidden=0");
>           if (is_array($row)) {
>               $fileObject =
> $this->typo3FALRepository->findFileReferenceByUid($row['uid']);
change this to to:
$fileObject = $this->typo3FALRepository->findByRelation('<your table 
name>', 'file', $this->getUid());
And it will be much cleaner and not so likely to break as it is a pulic 
API.
'file' here again is the field name defined in TCA.
>               $fileObjectData = $fileObject->toArray();
You can do that, but using the object directly should be fine, too.
Kind regards,
Helmut
-- 
Helmut Hummel
Release Manager TYPO3 6.0
TYPO3 Core Developer, TYPO3 Security Team Member
TYPO3 .... inspiring people to share!
Get involved: typo3.org
    
    
More information about the TYPO3-dev
mailing list