|
23 | 23 | * This copyright notice MUST APPEAR in all copies of the script! |
24 | 24 | ***************************************************************/ |
25 | 25 |
|
| 26 | +use Psr\Http\Message\ServerRequestInterface; |
| 27 | + |
26 | 28 | /** |
27 | 29 | * Gridelements indexer. |
28 | 30 | * |
@@ -148,13 +150,42 @@ protected function getGridelementElementContent( |
148 | 150 | array $record, |
149 | 151 | array $options |
150 | 152 | ) { |
151 | | - $pageIdOfRecord = $record['pid']; |
| 153 | + $pageIdOfRecord = (int) $record['pid']; |
152 | 154 | tx_mksearch_util_Indexer::prepareTSFE($pageIdOfRecord, $options['lang'] ?? 0); |
153 | 155 |
|
154 | | - $allowedCTypes = $this->getAllowedCTypes($options); |
155 | | - |
156 | 156 | /** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj */ |
157 | 157 | $cObj = $GLOBALS['TSFE']->cObj; |
| 158 | + $setup = $this->getTypoScriptConfiguration($cObj, $options, $pageIdOfRecord); |
| 159 | + |
| 160 | + // This is needed so the BackendConfigurationManager loads the TypoScript for the current tt_content |
| 161 | + // record during it's rendering and not for the page that is selected in the BE page tree. |
| 162 | + if (\Sys25\RnBase\Utility\TYPO3::isTYPO121OrHigher()) { |
| 163 | + $originalRequest = $cObj->getRequest(); |
| 164 | + $originalPageId = null; |
| 165 | + } else { |
| 166 | + $originalPageId = $_POST['id'] ?? null; |
| 167 | + $originalRequest = null; |
| 168 | + } |
| 169 | + $this->populatePageIdOfRecord($cObj, $pageIdOfRecord); |
| 170 | + |
| 171 | + $cObj->start($record, 'tt_content'); |
| 172 | + |
| 173 | + $content = $cObj->cObjGetSingle( |
| 174 | + $setup['tt_content.']['gridelements_pi1'], |
| 175 | + $setup['tt_content.']['gridelements_pi1.'] |
| 176 | + ); |
| 177 | + $this->resetPopulatedPageIdOfRecord($originalRequest, $originalPageId); |
| 178 | + |
| 179 | + return $content; |
| 180 | + } |
| 181 | + |
| 182 | + protected function getTypoScriptConfiguration( |
| 183 | + \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj, |
| 184 | + array $options, |
| 185 | + int $pageIdOfRecord |
| 186 | + ): array { |
| 187 | + $allowedCTypes = $this->getAllowedCTypes($options); |
| 188 | + |
158 | 189 | $setup = \Sys25\RnBase\Utility\TYPO3::isTYPO121OrHigher() |
159 | 190 | ? $cObj->getRequest()->getAttribute('frontend.typoscript')->getSetupArray() |
160 | 191 | : $GLOBALS['TSFE']->tmpl->setup; |
@@ -183,40 +214,56 @@ protected function getGridelementElementContent( |
183 | 214 | $frontendTypoScript->setSetupArray($setup); |
184 | 215 | $cObj->setRequest($cObj->getRequest()->withAttribute('frontend.typoscript', $frontendTypoScript)); |
185 | 216 | } |
| 217 | + |
| 218 | + // Put in runtime cache for TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager so |
| 219 | + // includeCTypesInGridelementRendering is available at this point |
| 220 | + \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache( |
| 221 | + 'runtime' |
| 222 | + )->set('extbase-backend-typoscript-pageId-'.$pageIdOfRecord, $setup); |
186 | 223 | } |
187 | 224 |
|
188 | | - // This is needed so the BackendConfigurationManager loads the TypoScript for the current tt_content |
189 | | - // record during it's rendering and not for the page that is selected in the BE page tree. |
| 225 | + return $setup; |
| 226 | + } |
| 227 | + |
| 228 | + /** |
| 229 | + * This is needed so the BackendConfigurationManager loads the TypoScript for the current tt_content |
| 230 | + * record during it's rendering and not for the page that is selected in the BE page tree. |
| 231 | + */ |
| 232 | + protected function populatePageIdOfRecord( |
| 233 | + \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj, |
| 234 | + int $pageIdOfRecord |
| 235 | + ): void { |
190 | 236 | if (\Sys25\RnBase\Utility\TYPO3::isTYPO121OrHigher()) { |
191 | | - $originalRequest = $cObj->getRequest(); |
192 | 237 | $configurationManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( |
193 | 238 | \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::class |
194 | 239 | ); |
195 | | - $configurationManager->setRequest($originalRequest->withParsedBody(array_merge( |
196 | | - $originalRequest->getParsedBody() ?? [], |
| 240 | + $configurationManager->setRequest($cObj->getRequest()->withParsedBody(array_merge( |
| 241 | + $cObj->getRequest()->getParsedBody() ?? [], |
197 | 242 | ['id' => $pageIdOfRecord] |
198 | 243 | ))); |
199 | 244 | } else { |
200 | | - $originalPageId = $_POST['id'] ?? null; |
201 | 245 | $_POST['id'] = $pageIdOfRecord; |
202 | 246 | } |
| 247 | + } |
203 | 248 |
|
204 | | - $cObj->start($record, 'tt_content'); |
205 | | - |
206 | | - $content = $cObj->cObjGetSingle( |
207 | | - $setup['tt_content.']['gridelements_pi1'], |
208 | | - $setup['tt_content.']['gridelements_pi1.'] |
209 | | - ); |
| 249 | + /** |
| 250 | + * Make sure to reset the request/id so the configuration manager will load the TypoScript for the page that is |
| 251 | + * selected in the BE page tree if it's needed after this point. |
| 252 | + */ |
| 253 | + protected function resetPopulatedPageIdOfRecord( |
| 254 | + ?ServerRequestInterface $originalRequest, |
| 255 | + ?int $originalPageId |
| 256 | + ): void { |
210 | 257 | // Make sure to reset the request/id so the configuration manager will load the TypoScript for the page that is |
211 | 258 | // selected in the BE page tree if it's needed after this point. |
212 | | - if (isset($originalRequest) && isset($configurationManager)) { |
| 259 | + if (\Sys25\RnBase\Utility\TYPO3::isTYPO121OrHigher()) { |
| 260 | + $configurationManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( |
| 261 | + \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::class |
| 262 | + ); |
213 | 263 | $configurationManager->setRequest($originalRequest); |
214 | | - } |
215 | | - if (isset($originalPageId)) { |
| 264 | + } else { |
216 | 265 | $_POST['id'] = $originalPageId; |
217 | 266 | } |
218 | | - |
219 | | - return $content; |
220 | 267 | } |
221 | 268 |
|
222 | 269 | /** |
|
0 commit comments