-
Notifications
You must be signed in to change notification settings - Fork 638
/
ContentContentObject.php
158 lines (146 loc) · 6.26 KB
/
ContentContentObject.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Frontend\ContentObject;
use Psr\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\Event\ModifyRecordsAfterFetchingContentEvent;
/**
* Contains CONTENT class object.
*/
class ContentContentObject extends AbstractContentObject
{
/**
* Rendering the cObject, CONTENT
*
* @param array $conf Array of TypoScript properties
* @return string Output
*/
public function render($conf = [])
{
if (!empty($conf['if.']) && !$this->cObj->checkIf($conf['if.'])) {
return '';
}
$frontendController = $this->getTypoScriptFrontendController();
$theValue = '';
$originalRec = $frontendController->currentRecord;
// If the currentRecord is set, we register, that this record has invoked this function.
// It should not be allowed to do this again then!!
if ($originalRec) {
if (isset($frontendController->recordRegister[$originalRec])) {
++$frontendController->recordRegister[$originalRec];
} else {
$frontendController->recordRegister[$originalRec] = 1;
}
}
$conf['table'] = trim((string)$this->cObj->stdWrapValue('table', $conf));
$conf['select.'] = !empty($conf['select.']) ? $conf['select.'] : [];
$renderObjName = ($conf['renderObj'] ?? false) ? $conf['renderObj'] : '<' . $conf['table'];
$renderObjKey = ($conf['renderObj'] ?? false) ? 'renderObj' : '';
$renderObjConf = $conf['renderObj.'] ?? [];
$slide = (int)$this->cObj->stdWrapValue('slide', $conf);
if (!$slide) {
$slide = 0;
}
$slideCollect = (int)$this->cObj->stdWrapValue('collect', $conf['slide.'] ?? []);
if (!$slideCollect) {
$slideCollect = 0;
}
$slideCollectReverse = (bool)$this->cObj->stdWrapValue('collectReverse', $conf['slide.'] ?? []);
$slideCollectFuzzy = (bool)$this->cObj->stdWrapValue('collectFuzzy', $conf['slide.'] ?? []);
if (!$slideCollect) {
$slideCollectFuzzy = true;
}
$again = false;
$tmpValue = '';
do {
$cobjValue = '';
$modifyRecordsEvent = GeneralUtility::makeInstance(EventDispatcherInterface::class)->dispatch(
new ModifyRecordsAfterFetchingContentEvent(
$this->cObj->getRecords($conf['table'], $conf['select.']),
$theValue,
$slide,
$slideCollect,
$slideCollectReverse,
$slideCollectFuzzy,
$conf
)
);
$records = $modifyRecordsEvent->getRecords();
$theValue = $modifyRecordsEvent->getFinalContent();
$slide = $modifyRecordsEvent->getSlide();
$slideCollect = $modifyRecordsEvent->getSlideCollect();
$slideCollectReverse = $modifyRecordsEvent->getSlideCollectReverse();
$slideCollectFuzzy = $modifyRecordsEvent->getSlideCollectFuzzy();
$conf = $modifyRecordsEvent->getConfiguration();
if ($records !== []) {
$this->getTimeTracker()->setTSlogMessage('NUMROWS: ' . count($records));
$cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class, $frontendController);
$cObj->setParent($this->cObj->data, $this->cObj->currentRecord);
$this->cObj->currentRecordNumber = 0;
foreach ($records as $row) {
$registerField = $conf['table'] . ':' . ($row['uid'] ?? 0);
if (!($frontendController->recordRegister[$registerField] ?? false)) {
$this->cObj->currentRecordNumber++;
$cObj->parentRecordNumber = $this->cObj->currentRecordNumber;
$frontendController->currentRecord = $registerField;
$this->cObj->lastChanged($row['tstamp'] ?? 0);
$cObj->setRequest($this->request);
$cObj->start($row, $conf['table']);
$tmpValue = $cObj->cObjGetSingle($renderObjName, $renderObjConf, $renderObjKey);
$cobjValue .= $tmpValue;
}
}
}
if ($slideCollectReverse) {
$theValue = $cobjValue . $theValue;
} else {
$theValue .= $cobjValue;
}
if ($slideCollect > 0) {
$slideCollect--;
}
if ($slide) {
if ($slide > 0) {
$slide--;
}
$conf['select.']['pidInList'] = $this->cObj->getSlidePids(
$conf['select.']['pidInList'] ?? '',
$conf['select.']['pidInList.'] ?? [],
);
if (isset($conf['select.']['pidInList.'])) {
unset($conf['select.']['pidInList.']);
}
$again = (string)$conf['select.']['pidInList'] !== '';
}
} while ($again && $slide && ((string)$tmpValue === '' && $slideCollectFuzzy || $slideCollect));
$wrap = $this->cObj->stdWrapValue('wrap', $conf);
if ($wrap) {
$theValue = $this->cObj->wrap($theValue, $wrap);
}
if (isset($conf['stdWrap.'])) {
$theValue = $this->cObj->stdWrap($theValue, $conf['stdWrap.']);
}
// Restore
$frontendController->currentRecord = $originalRec;
if ($originalRec) {
--$frontendController->recordRegister[$originalRec];
}
return $theValue;
}
protected function getTimeTracker(): TimeTracker
{
return GeneralUtility::makeInstance(TimeTracker::class);
}
}