-
-
Save grimmcreative/ef1e00fb7f3242f5196695ae94e8a27f to your computer and use it in GitHub Desktop.
TYPO3 FAL use localized fileReferences for pages table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; | |
use TYPO3\CMS\Extbase\Domain\Model\FileReference; | |
use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy; | |
class Page extends AbstractEntity | |
{ | |
/** | |
* @var \TYPO3\CMS\Extbase\Domain\Model\FileReference | |
*/ | |
protected $myImage; | |
/** | |
* @return \TYPO3\CMS\Extbase\Domain\Model\FileReference | |
*/ | |
public function getMyImage() | |
{ | |
$fileReference = $this->findFileReference('my_image'); | |
if (is_null($fileReference)) { | |
return null; | |
} | |
$this->setMyImage($fileReference); | |
if ($this->myImage instanceof LazyLoadingProxy) { | |
$this->myImage->_loadRealInstance(); | |
} | |
return $this->myImage->getOriginalResource(); | |
} | |
/** | |
* @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $myImage | |
* @return void | |
*/ | |
public function setMyImage(FileReference $myImage) | |
{ | |
$this->myImage = $myImage; | |
} | |
/** | |
* @param string $column | |
* @return null|FileReference | |
*/ | |
private function findFileReference($column = 'my_image') | |
{ | |
$this->pageHandler->sys_language_uid = $GLOBALS['TSFE']->sys_language_uid; | |
/** @var array $pageRecord */ | |
$pageRecord = $this->pageHandler->getPage($this->getUid()); | |
$uid = $this->getUid(); | |
$table = 'pages'; | |
if ($this->isPageRecordTranslatable($pageRecord)) { | |
$uid = (int)$pageRecord['_PAGES_OVERLAY_UID']; | |
$table = 'pages_language_overlay'; | |
} | |
$fileObject = $this->fileRepository->findByRelation( | |
$table, | |
$column, | |
$uid | |
); | |
if (!is_array($fileObject) || count($fileObject) === 0) { | |
return null; | |
} | |
/** @var \TYPO3\CMS\Core\Resource\FileReference $fileResource */ | |
$fileResource = $fileObject[0]; | |
$fileReference = new FileReference(); | |
$fileReference->setOriginalResource($fileResource); | |
return $fileReference; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment