GalleryProcessor implements DataProcessorInterface
This data processor will calculate rows, columns and dimensions for a gallery based on several settings and can be used for f.i. the CType "textmedia"
The output will be an array which contains the rows and columns, including the file references and the calculated width and height for each media element, but also some more information of the gallery, like position, width and counters
Example TypoScript configuration:
10 = TYPO3\CMS\Frontend\DataProcessing\GalleryProcessor 10 { filesProcessedDataKey = files mediaOrientation.field = imageorient numberOfColumns.field = imagecols equalMediaHeight.field = imageheight equalMediaWidth.field = imagewidth columnSpacing = 0 borderEnabled.field = imageborder borderPadding = 0 borderWidth = 0 maxGalleryWidth = {$styles.content.mediatext.maxW} maxGalleryWidthInText = {$styles.content.mediatext.maxWInText} as = gallery }
Output example:
gallery { position { horizontal = center vertical = above noWrap = FALSE } width = 600 count { files = 2 columns = 1 rows = 2 } rows { 1 { columns { 1 { media = TYPO3\CMS\Core\Resource\FileReference dimensions { width = 600 height = 400 } } } } 2 { columns { 1 { media = TYPO3\CMS\Core\Resource\FileReference dimensions { width = 600 height = 400 } } } } } columnSpacing = 0 border { enabled = FALSE width = 0 padding = 0 } }
Table of Contents
Interfaces
- DataProcessorInterface
- Interface for data processor classes processing data from ContentObjectRenderer, used e.g. with the FLUIDTEMPLATE content object
Properties
- $availableGalleryPositions : array<string|int, mixed>
- Matching the tt_content field towards the imageOrient option
- $borderEnabled : bool
- $borderPadding : int
- $borderWidth : int
- $columnSpacing : int
- $contentObjectRenderer : ContentObjectRenderer
- The content object renderer
- $cropVariant : string
- $equalMediaHeight : int
- $equalMediaWidth : int
- $fileObjects : array<string|int, FileInterface>
- The (filtered) media files to be used in the gallery
- $galleryData : array<string|int, mixed>
- Storage for processed data
- $maxGalleryWidth : int
- $maxGalleryWidthInText : int
- $mediaDimensions : array<string|int, mixed>
- The calculated dimensions for each media element
- $mediaOrientation : int
- $numberOfColumns : int
- $processorConfiguration : array<string|int, mixed>
- The processor configuration
Methods
- process() : array<string|int, mixed>
- Process data for a gallery, for instance the CType "textmedia"
- calculateMediaWidthsAndHeights() : mixed
- Calculate the width/height of the media elements
- calculateRowsAndColumns() : mixed
- Calculate the amount of rows and columns
- determineGalleryPosition() : mixed
- Define the gallery position
- determineMaximumGalleryWidth() : mixed
- Get the gallery width based on vertical position
- getConfigurationValue() : string
- Get configuration value from processorConfiguration with when $dataArrayKey fallback to value from cObj->data array
- getCroppedDimensionalProperty() : int
- When retrieving the height or width for a media file a possible cropping needs to be taken into account.
- prepareGalleryData() : mixed
- Prepare the gallery data
Properties
$availableGalleryPositions
Matching the tt_content field towards the imageOrient option
protected
array<string|int, mixed>
$availableGalleryPositions
= ['horizontal' => ['center' => [0, 8], 'right' => [1, 9, 17, 25], 'left' => [2, 10, 18, 26]], 'vertical' => ['above' => [0, 1, 2], 'intext' => [17, 18, 25, 26], 'below' => [8, 9, 10]]]
$borderEnabled
protected
bool
$borderEnabled
$borderPadding
protected
int
$borderPadding
$borderWidth
protected
int
$borderWidth
$columnSpacing
protected
int
$columnSpacing
$contentObjectRenderer
The content object renderer
protected
ContentObjectRenderer
$contentObjectRenderer
$cropVariant
protected
string
$cropVariant
= 'default'
$equalMediaHeight
protected
int
$equalMediaHeight
$equalMediaWidth
protected
int
$equalMediaWidth
$fileObjects
The (filtered) media files to be used in the gallery
protected
array<string|int, FileInterface>
$fileObjects
= []
$galleryData
Storage for processed data
protected
array<string|int, mixed>
$galleryData
= ['position' => ['horizontal' => '', 'vertical' => '', 'noWrap' => false], 'width' => 0, 'count' => ['files' => 0, 'columns' => 0, 'rows' => 0], 'columnSpacing' => 0, 'border' => ['enabled' => false, 'width' => 0, 'padding' => 0], 'rows' => []]
$maxGalleryWidth
protected
int
$maxGalleryWidth
$maxGalleryWidthInText
protected
int
$maxGalleryWidthInText
$mediaDimensions
The calculated dimensions for each media element
protected
array<string|int, mixed>
$mediaDimensions
= []
$mediaOrientation
protected
int
$mediaOrientation
$numberOfColumns
protected
int
$numberOfColumns
$processorConfiguration
The processor configuration
protected
array<string|int, mixed>
$processorConfiguration
Methods
process()
Process data for a gallery, for instance the CType "textmedia"
public
process(ContentObjectRenderer $cObj, array<string|int, mixed> $contentObjectConfiguration, array<string|int, mixed> $processorConfiguration, array<string|int, mixed> $processedData) : array<string|int, mixed>
Parameters
- $cObj : ContentObjectRenderer
-
The content object renderer, which contains data of the content element
- $contentObjectConfiguration : array<string|int, mixed>
-
The configuration of Content Object
- $processorConfiguration : array<string|int, mixed>
-
The configuration of this processor
- $processedData : array<string|int, mixed>
-
Key/value store of processed data (e.g. to be passed to a Fluid View)
Tags
Return values
array<string|int, mixed> —the processed data as key/value store
calculateMediaWidthsAndHeights()
Calculate the width/height of the media elements
protected
calculateMediaWidthsAndHeights() : mixed
Based on the width of the gallery, defined equal width or height by a user, the spacing between columns and the use of a border, defined by user, where the border width and padding are taken into account
File objects MUST already be filtered. They need a height and width to be shown in the gallery
calculateRowsAndColumns()
Calculate the amount of rows and columns
protected
calculateRowsAndColumns() : mixed
determineGalleryPosition()
Define the gallery position
protected
determineGalleryPosition() : mixed
Gallery has a horizontal and a vertical position towards the text and a possible wrapping of the text around the gallery.
determineMaximumGalleryWidth()
Get the gallery width based on vertical position
protected
determineMaximumGalleryWidth() : mixed
getConfigurationValue()
Get configuration value from processorConfiguration with when $dataArrayKey fallback to value from cObj->data array
protected
getConfigurationValue(string $key[, string|null $dataArrayKey = null ]) : string
Parameters
- $key : string
- $dataArrayKey : string|null = null
Return values
stringgetCroppedDimensionalProperty()
When retrieving the height or width for a media file a possible cropping needs to be taken into account.
protected
getCroppedDimensionalProperty(FileInterface $fileObject, string $dimensionalProperty) : int
Parameters
- $fileObject : FileInterface
- $dimensionalProperty : string
-
'width' or 'height'
Return values
intprepareGalleryData()
Prepare the gallery data
protected
prepareGalleryData() : mixed
Make an array for rows, columns and configuration