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