Skip to content
Snippets Groups Projects
Commit eb60cd1f authored by Steffen Ritter's avatar Steffen Ritter Committed by Francois Suter
Browse files

[FEATURE] Add begin/maxItems options to FILES ContentObject

The FILES ContentObject always renders all files. If you access
the media field of a page you probably only want to render the
first attached file. This patch adds begin and maxItems as properties
to TypoScript.

Releases: 6.2
Resolves: #52632
Documentation: #52742
Change-Id: I9755571d5a1a692fbd4b5ea2b3ef82cc99fa2cc1
Reviewed-on: https://review.typo3.org/24558
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
Reviewed-by: Francois Suter
Tested-by: Francois Suter
parent 3bc111bc
Branches
Tags
No related merge requests found
......@@ -28,6 +28,7 @@ namespace TYPO3\CMS\Frontend\ContentObject;
***************************************************************/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
/**
* Contains FILES content object
......@@ -156,9 +157,34 @@ class FilesContentObject extends \TYPO3\CMS\Frontend\ContentObject\AbstractConte
});
}
$GLOBALS['TSFE']->register['FILES_COUNT'] = count($fileObjects);
$availableFileObjectCount = count($fileObjects);
$start = 0;
if (array_key_exists('begin', $conf)) {
$start = intval($conf['begin']);
}
if (array_key_exists('begin.', $conf)) {
$start = intval($this->cObj->stdWrap($start, $conf['begin.']));
}
$start = MathUtility::forceIntegerInRange($start, 0, $availableFileObjectCount);
$limit = $availableFileObjectCount;
if (array_key_exists('maxItems', $conf)) {
$limit = intval($conf['maxItems']);
}
if (array_key_exists('maxItems.', $conf)) {
$limit = intval($this->cObj->stdWrap($limit, $conf['maxItems.']));
}
$end = MathUtility::forceIntegerInRange($start + $limit, 0, $availableFileObjectCount);
$GLOBALS['TSFE']->register['FILES_COUNT'] = $limit < $availableFileObjectCount ? $limit : $availableFileObjectCount;
$fileObjectCounter = 0;
foreach ($fileObjects as $key => $fileObject) {
$keys = array_keys($fileObjects);
for ($i = $start; $i < $end; $i++) {
$key = $keys[$i];
$fileObject = $fileObjects[$key];
$GLOBALS['TSFE']->register['FILE_NUM_CURRENT'] = $fileObjectCounter;
$this->cObj->setCurrentFile($fileObject);
$content .= $this->cObj->cObjGetSingle($splitConf[$key]['renderObj'], $splitConf[$key]['renderObj.']);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment