[BUGFIX] Fix image rendering for renderMethod = table 07/35407/4
authorTorben Hansen <derhansen@gmail.com>
Sun, 14 Dec 2014 11:57:32 +0000 (12:57 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Thu, 1 Jan 2015 18:45:04 +0000 (19:45 +0100)
Since the introduction of FAL to TYPO3, the rendering of images
using CSS styled content with renderMethod = table is broken.

Using a single image results in the image being rendered twice
and if you have multiple images in one content object, only the
last image is rendered multiple times (depending on the amount
of images in the content object).

This patch resolves both issues and loads the current image file
reference to the contentObjectRenderer while looping through the
images of the content object.

Resolves: #46864
Related: #47004
Releases: master, 6.2
Change-Id: If120267111e30de6438cecc5e14cea34bc6fa235
Reviewed-on: http://review.typo3.org/35407
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/frontend/Classes/ContentObject/ImageTextContentObject.php

index 5e434b5..b102e49 100644 (file)
@@ -37,7 +37,7 @@ class ImageTextContentObject extends AbstractContentObject {
                }
                $imgList = isset($conf['imgList.']) ? trim($this->cObj->stdWrap($conf['imgList'], $conf['imgList.'])) : trim($conf['imgList']);
                if ($imgList) {
-                       $imgs = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $imgList);
+                       $imgs = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $imgList, TRUE);
                        $imgStart = isset($conf['imgStart.']) ? (int)$this->cObj->stdWrap($conf['imgStart'], $conf['imgStart.']) : (int)$conf['imgStart'];
                        $imgCount = count($imgs) - $imgStart;
                        $imgMax = isset($conf['imgMax.']) ? (int)$this->cObj->stdWrap($conf['imgMax'], $conf['imgMax.']) : (int)$conf['imgMax'];
@@ -182,6 +182,9 @@ class ImageTextContentObject extends AbstractContentObject {
                                $GLOBALS['TSFE']->register['IMAGE_NUM'] = $a;
                                $GLOBALS['TSFE']->register['IMAGE_NUM_CURRENT'] = $a;
                                $imgKey = $a + $imgStart;
+                               if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($imgs[$imgKey])) {
+                                       $this->setCurrentFileInContentObjectRenderer(intval($imgs[$imgKey]));
+                               }
                                $totalImagePath = $imgPath . $imgs[$imgKey];
                                $this->cObj->data[$this->cObj->currentValKey] = $totalImagePath;
                                $imgObjNum = (int)$splitArr[$a]['imgObjNum'];
@@ -469,4 +472,17 @@ class ImageTextContentObject extends AbstractContentObject {
                return $output;
        }
 
+       /**
+        * Loads the file reference object and sets it in the
+        * currentFile property of the ContentObjectRenderer.
+        *
+        * This makes the file data available during image rendering.
+        *
+        * @param int $fileUid The UID of the file reference that should be loaded.
+        * @return void
+        */
+       protected function setCurrentFileInContentObjectRenderer($fileUid) {
+               $imageFile = $this->fileFactory->getFileReferenceObject($fileUid);
+               $this->cObj->setCurrentFile($imageFile);
+       }
 }