[FEATURE] Add begin/maxItems options to FILES ContentObject 58/24558/5
authorSteffen Ritter <info@rs-websystems.de>
Fri, 11 Oct 2013 10:17:56 +0000 (12:17 +0200)
committerFrancois Suter <francois@typo3.org>
Tue, 15 Oct 2013 09:33:23 +0000 (11:33 +0200)
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
typo3/sysext/frontend/Classes/ContentObject/FilesContentObject.php

index ae10a83..2b2f362 100644 (file)
@@ -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.']);