Hi,
dazu mein Beispiel in Typo3 6.0.2. Wie MajPay erwähnt, nicht persistent nur als Getter:
TCA:
'image' => array(
'label' => 'LLL:EXT:lang/locallang_general.xml:LGL.images',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('image', array(
'appearance' => array(
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
),
'foreign_types' => array(
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
),
)
), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
),
Model:
class MyModel extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* @var \TYPO3\CMS\Core\Resource\FileRepository
* @inject
*/
protected $typo3FALRepository;
/**
* _image
*
* @var \array
*/
protected $_image;
/**
* Returns the image
*
* @return \array<\TYPO3\CMS\Extbase\Domain\Model\FileReference> $image
*/
public function getImage() {
if (count($this->_image)) {
return $this->_image;
}
$images = $this->typo3FALRepository->findByRelation("tx_extensionkey_domain_model_mymodel", "image", ($this->_localizedUid) ? $this->_localizedUid : $this->getUid());
if ($images) {
foreach ($images as $imageObject) {
try {
$this->_image[] = $imageObject->toArray();
} catch (Exception $e) {
// it is possible the url is moved or removed
}
}
}
return $this->_image;
}
}
Hier ist darauf zu achten, dass findByRelation() die lokalisierte UID des Models erwartet, um auch die lokalisierte fileRelation zu bekommen.
Parameter im fileRelation wie url, title, alternative werden mit toArray() gesetzt und stehen dann im View zur Verfügung.
View:
{namespace tx = VENDOR\Extension\ViewHelpers}
<f:for each="{mymodel.image}" as="image">
<div class="image">
<f:if condition="{image.link}">
<f:then>
<tx:typolink parameter="{image.link}"><f:image src="{image.url}" alt="{image.alternative}" title="{image.title}" width="200" /></tx:typolink>
</f:then>
<f:else>
<f:image src="{image.url}" alt="{image.alternative}" title="{image.title}" width="200" />
</f:else>
</f:if>
</div>
</f:for>
Der TypolinkViewHelper ist eine superfeine Sache, die ich hier fand:
https://github.com/castiron/cicbase/blob/master/Classes/ViewHelpers/TypolinkViewHelper.php
Edith sagt: Im ViewHelper hat der Namespace Einzug gehalten. Demnach muss es wie folgt aussehen:
<?php
namespace VENDOR\ExtensionKey\ViewHelpers;
/* *
* This script belongs to the FLOW3 package "Fluid". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License, or (at your *
* option) any later version. *
* *
* This script is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
* General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with the script. *
* If not, see http://www.gnu.org/licenses/lgpl.html *
* *
* The TYPO3 project - inspiring people to share! *
* */
/**
* Wraps some of the basic Typolink settings in a viewhelper. Good for rendering links to pages and page titles
* when all you have is the page id.
*/
class TypolinkViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
/**
* @param string $parameter
* @param string $target
* @param int $noCache
* @param int $useCacheHash
* @param array $additionalParams
* @param string $ATagParams
* @return mixed
*/
public function render($parameter, $target='',$noCache=0,$useCacheHash=1,$additionalParams=array(),$ATagParams = '') {
$typoLinkConf = array(
'parameter' => $parameter,
);
if($target) {
$typoLinkConf['target'] = $target;
}
if($noCache) {
$typoLinkConf['no_cache'] = 1;
}
if($useCacheHash) {
$typoLinkConf['useCacheHash'] = 1;
}
if(count($additionalParams)) {
$typoLinkConf['additionalParams'] = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('',$additionalParams);
}
if(strlen($ATagParams)) {
$typoLinkConf['ATagParams'] = $ATagParams;
}
$linkText = $this->renderChildren();
$textContentConf = array(
'typolink.' => $typoLinkConf,
'value' => $linkText
);
return $GLOBALS['TSFE']->cObj->cObjGetSingle('TEXT',$textContentConf);
}
}
?>
LG sun