[FEATURE] Providing Core Resource FileReference functionality
authorBenjamin Rau <rau@codearts.at>
Thu, 7 Mar 2013 12:19:25 +0000 (13:19 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 15 Mar 2013 19:39:26 +0000 (20:39 +0100)
Retrieve file information from Core\Resource by creating
a FAL resource object on the fly when needed.

You can access properties or getters of the object in Fluid
easily with the dot notation:

E.g.:

{myEntity.fileProperty.originalResource.title}
{myEntity.fileProperty.originalResource.properties.identifier}

Resolves: #46102
Releases: 6.1, 6.0
Change-Id: I33ff6a088e61715513446ae7600d3d21cbcfcd5a
Reviewed-on: https://review.typo3.org/18779
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Domain/Model/File.php
typo3/sysext/extbase/Classes/Domain/Model/FileReference.php

index e3619c1..3ded5a6 100644 (file)
@@ -4,7 +4,7 @@ namespace TYPO3\CMS\Extbase\Domain\Model;
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2010-2012 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
+ *  (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
  *  Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
  *  All rights reserved
  *
@@ -34,6 +34,22 @@ namespace TYPO3\CMS\Extbase\Domain\Model;
  */
 class File extends \TYPO3\CMS\Extbase\Domain\Model\AbstractFileFolder {
 
+       /**
+        * @var \TYPO3\CMS\Core\Resource\FileRepository
+        * @inject
+        */
+       protected $fileRepository;
+
+       /**
+        * @return \TYPO3\CMS\Core\Resource\File
+        */
+       public function getOriginalResource() {
+               if ($this->originalResource === NULL) {
+                       $this->originalResource = $this->fileRepository->findByUid($this->getUid());
+               }
+
+               return $this->originalResource;
+       }
 }
 
 ?>
\ No newline at end of file
index 66e1564..7b70842 100644 (file)
@@ -4,7 +4,7 @@ namespace TYPO3\CMS\Extbase\Domain\Model;
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2010-2012 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
+ *  (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
  *  Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
  *  All rights reserved
  *
@@ -34,6 +34,22 @@ namespace TYPO3\CMS\Extbase\Domain\Model;
  */
 class FileReference extends \TYPO3\CMS\Extbase\Domain\Model\AbstractFileFolder {
 
+       /**
+        * @var \TYPO3\CMS\Core\Resource\FileRepository
+        * @inject
+        */
+       protected $fileRepository;
+
+       /**
+        * @return \TYPO3\CMS\Core\Resource\FileReference
+        */
+       public function getOriginalResource() {
+               if ($this->originalResource === NULL) {
+                       $this->originalResource = $this->fileRepository->findFileReferenceByUid($this->getUid());
+               }
+
+               return $this->originalResource;
+       }
 }
 
 ?>
\ No newline at end of file