[FEATURE] Providing Core Resource FileReference functionality
authorBenjamin Rau <rau@codearts.at>
Thu, 7 Mar 2013 12:19:25 +0000 (13:19 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sun, 28 Apr 2013 12:42:50 +0000 (14:42 +0200)
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/20257
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/extbase/Classes/Domain/Model/File.php
typo3/sysext/extbase/Classes/Domain/Model/FileReference.php

index 5644df7..1fac92c 100644 (file)
@@ -4,7 +4,8 @@ namespace TYPO3\CMS\Extbase\Domain\Model;
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2012 Oliver Hader <oliver.hader@typo3.org>
+ *  (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
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -30,6 +31,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 0ecdcc3..cf1f9d9 100644 (file)
@@ -4,7 +4,8 @@ namespace TYPO3\CMS\Extbase\Domain\Model;
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2012 Oliver Hader <oliver.hader@typo3.org>
+ *  (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
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -30,6 +31,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