From eb60cd1f02b2bb4f9e624349ce6c2eb6be3291a7 Mon Sep 17 00:00:00 2001 From: Steffen Ritter <info@rs-websystems.de> Date: Fri, 11 Oct 2013 12:17:56 +0200 Subject: [PATCH] [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 --- .../ContentObject/FilesContentObject.php | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/typo3/sysext/frontend/Classes/ContentObject/FilesContentObject.php b/typo3/sysext/frontend/Classes/ContentObject/FilesContentObject.php index ae10a83397e7..2b2f362c00be 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/FilesContentObject.php +++ b/typo3/sysext/frontend/Classes/ContentObject/FilesContentObject.php @@ -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.']); -- GitLab