[BUGFIX] Fix header thumbnail for new inserted records
authorHelmut Hummel <helmut.hummel@typo3.org>
Wed, 21 Nov 2012 09:24:16 +0000 (10:24 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Wed, 21 Nov 2012 22:47:37 +0000 (23:47 +0100)
The header thumbnail is not correctly rendered when
inserting new images because the code tries to fetch
the record which is not created yet.

Use the data of the temporary record instead, to be able to
correctly create the thumbnail in the header.

Fixes: #43189
Releases: 6.0

Change-Id: Ic75fd6c70c8c10777a762f585c4c4b3ec467fe75
Reviewed-on: http://review.typo3.org/16657
Tested-by: Anja Leichsenring
Reviewed-by: Anja Leichsenring
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Stefan Neufeind
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/backend/Classes/Form/Element/InlineElement.php

index d9361de..97f18c6 100644 (file)
@@ -539,29 +539,30 @@ class InlineElement {
                }
                // Renders a thumbnail for the header
                if (!empty($config['appearance']['headerThumbnail']['field'])) {
-                       $originalRecord = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($foreign_table, $rec['uid']);
-                       if (is_array($originalRecord)) {
-                               $fileUid = $originalRecord[$config['appearance']['headerThumbnail']['field']];
-                               list($fileUid) = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $fileUid);
-                               if ($fileUid) {
-                                       $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObject($fileUid);
-                                       if ($fileObject) {
-                                               $imageSetup = $config['appearance']['headerThumbnail'];
-                                               unset($imageSetup['field']);
-                                               $imageSetup = array_merge(array('width' => 64, 'height' => 64), $imageSetup);
-                                               $imageUrl = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, $imageSetup)->getPublicUrl(TRUE);
-                                               $thumbnail = '<img src="' . $imageUrl . '" alt="' . htmlspecialchars($recTitle) . '">';
-                                       } else {
-                                               $thumbnail = FALSE;
-                                       }
+                       $fieldValue = $rec[$config['appearance']['headerThumbnail']['field']];
+                       $firstElement = array_shift(\TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $fieldValue));
+                       $fileUid = array_pop(\TYPO3\CMS\Backend\Utility\BackendUtility::splitTable_Uid($firstElement));
+                       if (!empty($fileUid)) {
+                               $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObject($fileUid);
+                               if ($fileObject) {
+                                       $imageSetup = $config['appearance']['headerThumbnail'];
+                                       unset($imageSetup['field']);
+                                       $imageSetup = array_merge(array('width' => 64, 'height' => 64), $imageSetup);
+                                       $imageUrl = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, $imageSetup)->getPublicUrl(TRUE);
+                                       $thumbnail = '<img src="' . $imageUrl . '" alt="' . htmlspecialchars($recTitle) . '">';
+                               } else {
+                                       $thumbnail = FALSE;
                                }
                        }
+
                }
                $altText = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordIconAltText($rec, $foreign_table);
                $iconImg = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord($foreign_table, $rec, array('title' => htmlspecialchars($altText), 'id' => $objectId . '_icon'));
                $label = '<span id="' . $objectId . '_label">' . $recTitle . '</span>';
                $ctrl = $this->renderForeignRecordHeaderControl($parentUid, $foreign_table, $rec, $config, $isVirtualRecord);
-               $header = '<table>' . '<tr>' . (!empty($config['appearance']['headerThumbnail']['field']) && $thumbnail ? '<td class="t3-form-field-header-inline-thumbnail" id="' . $objectId . '_thumbnailcontainer">' . $thumbnail . '</td>' : '<td class="t3-form-field-header-inline-icon" id="' . $objectId . '_iconcontainer">' . $iconImg . '</td>') . '<td class="t3-form-field-header-inline-summary">' . $label . '</td>' . '<td clasS="t3-form-field-header-inline-ctrl">' . $ctrl . '</td>' . '</tr>' . '</table>';
+               $header = '<table>' . '<tr>' . (!empty($config['appearance']['headerThumbnail']['field']) && $thumbnail ?
+                               '<td class="t3-form-field-header-inline-thumbnail" id="' . $objectId . '_thumbnailcontainer">' . $thumbnail . '</td>' :
+                               '<td class="t3-form-field-header-inline-icon" id="' . $objectId . '_iconcontainer">' . $iconImg . '</td>') . '<td class="t3-form-field-header-inline-summary">' . $label . '</td>' . '<td clasS="t3-form-field-header-inline-ctrl">' . $ctrl . '</td>' . '</tr>' . '</table>';
                return $header;
        }