Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TCA, Model and Fluid Partial to display FAL images as a simple gallery using TYPO3 and Extbase 6.1
SQL:
images int(11) unsigned DEFAULT '0',
=======================================================
TCA
....
'images' => array(
'exclude' => 0,
'label' => 'images',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'images',
array(
'appearance' => array(
'headerThumbnail' => array(
'width' => '100',
'height' => '100',
),
'createNewRelationLinkTitle' => 'LLL:EXT:your_extension/Resources/Private/Language/locallang_db.xlf:tx_yourextension_db_table.add-images'
),
// custom configuration for displaying fields in the overlay/reference table
// to use the imageoverlayPalette instead of the basicoverlayPalette
'foreign_types' => array(
'0' => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
),
\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => array(
'showitem' => '
--palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
)
),
),
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
)
),
...
============================================================================
Model:
/**
* images to use in the gallery
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
* @lazy
*/
protected $images;
/**
* __construct
*
* @return AbstractObject
*/
public function __construct() {
$this->images = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
/**
* sets the Images
*
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $images
*
* @return void
*/
public function setImages($images) {
$this->images = $images;
}
/**
* get the Images
*
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
*/
public function getImages() {
return $this->images;
}
==============================================================================
Fluid View (this is a Partial, providing all images with a link to open it in a lightbox, classic clickenlarge):
<f:for each="{images}" as="image" >
<a href="{f:uri.image(src:image.uid,treatIdAsReference:1)}" class="lightbox" rel="gallery">
<f:image src="{image.uid}" alt="{image.originalResorce.alternative}" width='101' height="67" treatIdAsReference="1"/>
</a >
</f:for >
@kaystrobach

This comment has been minimized.

Copy link

@kaystrobach kaystrobach commented Jun 12, 2013

nice, should be posted to wiki.typo3.org -> thanks for taking care

@ganybhat

This comment has been minimized.

Copy link

@ganybhat ganybhat commented Jun 26, 2013

How to get pdf file link here, if we upload pdf file ?

@elbebass

This comment has been minimized.

Copy link

@elbebass elbebass commented Jul 19, 2013

Line 9 should be : ExtensionManagementUtility

@frans-beech-it

This comment has been minimized.

Copy link

@frans-beech-it frans-beech-it commented Aug 2, 2013

Here some additions to add your own translation/text for the "Create new relation" text and some other visual tweaks:

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('images', array(
            'appearance' => array(
                'headerThumbnail' => array(
                    'width' => '100',
                    'height' => '100',
                ),
                'createNewRelationLinkTitle' => 'LLL:EXT:your_extension/Resources/Private/Language/locallang_db.xlf:tx_yourextension_db_table.add-images'
            )
        ), 'jpg,jpeg,png'),

@stmllr

This comment has been minimized.

Copy link

@stmllr stmllr commented Oct 23, 2013

What I miss here is an Image domain model facade which

  • hides the complexity of \TYPO3\CMS\Extbase\Domain\Model\FileReference
  • uses domain specific language (DSL)

This would make the domain classes and template more readable.

@fedir

This comment has been minimized.

Copy link

@fedir fedir commented Oct 23, 2013

I made a simple extension "newsfal" (downloadable on TER) to add the support of FAL to news under TYPO3.x. It works under similar conventions.

@bernhardberger

This comment has been minimized.

Copy link

@bernhardberger bernhardberger commented Mar 19, 2014

Sorry to say, but your extension doesn't really work with the current systems (news 2.3.0 and TYPO3 6.1) anymore. I also took a look at the code and it isn't even close to standard conventions tbh.

@letsjump

This comment has been minimized.

Copy link

@letsjump letsjump commented May 2, 2014

Works perfectly on T3 6.1.7 or 6.1.8!
Thanks!

@hummelhb

This comment has been minimized.

Copy link

@hummelhb hummelhb commented Jun 26, 2014

Thanks for those helpful code examples. Tried this out but got into nasty translation issues.

When transating records and adding/modifying images the sys_language_uid value will always be set back to 0. In BE everything looks(!) fine, actually the relations are now broken. Trying to render the images of a translated record in FE will fail as the language uid of the file relation is now wrong.

Any idea how to solve this? At least translation handling of images works for standard CEs, so there should be a way to do it correctly for user created objects.

Using TYPO3 6.2.3

@Nioldur

This comment has been minimized.

Copy link

@Nioldur Nioldur commented Jan 24, 2015

Using the code above in Typo3 6.2.9, i get the following error message:
ForViewHelper only supports arrays and objects implementing \Traversable interface

Any idea how to solve this?

@koenig-digital

This comment has been minimized.

Copy link

@koenig-digital koenig-digital commented Nov 6, 2015

Got the "array" problem also - here is a newer version builded with extension builder ->

https://gist.github.com/koenig-digital/45b3bd8c5a28460148ca

@MiroslawKmiec

This comment has been minimized.

Copy link

@MiroslawKmiec MiroslawKmiec commented Nov 23, 2017

Builder creates files as one file relation: \TYPO3\CMS\Extbase\Domain\Model\FileReference, In TCA maxitems=1 only.
If you need more than one file, you should change model to use: \TYPO3\CMS\Extbase\Persistence\ObjectStorage and fix in TCA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment