Passed
Push — master ( d71159...795102 )
by
unknown
12:41
created

renderPageModulePreviewContent()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 27
rs 8.8333
cc 7
nc 6
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17
18
namespace TYPO3\CMS\Frontend\Preview;
19
20
use TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer;
21
use TYPO3\CMS\Backend\Utility\BackendUtility;
22
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
23
24
/**
25
 * Contains a preview rendering for the page module of CType="textpic"
26
 * @internal this is a concrete TYPO3 hook implementation and solely used for EXT:frontend and not part of TYPO3's Core API.
27
 */
28
class TextpicPreviewRenderer extends StandardContentPreviewRenderer
29
{
30
    public function renderPageModulePreviewContent(GridColumnItem $item): string
31
    {
32
        $content = '';
33
        $row = $item->getRecord();
34
        if ($row['bodytext']) {
35
            $content = $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
36
        }
37
38
        if ($row['image']) {
39
            $content .= $this->linkEditContent(BackendUtility::thumbCode($row, 'tt_content', 'image', '', '', null, 0, '', '', false), $row);
40
41
            $fileReferences = BackendUtility::resolveFileReferences('tt_content', 'image', $row);
42
43
            if (!empty($fileReferences)) {
44
                $linkedContent = '';
45
46
                foreach ($fileReferences as $fileReference) {
47
                    $description = $fileReference->getDescription();
48
                    if ($description !== null && $description !== '') {
49
                        $linkedContent .= htmlspecialchars($description) . '<br />';
50
                    }
51
                }
52
53
                $content .= $this->linkEditContent($linkedContent, $row);
54
            }
55
        }
56
        return $content;
57
    }
58
}
59