2626use TYPO3 \CMS \Core \Database \ConnectionPool ;
2727use TYPO3 \CMS \Core \Database \Query \QueryHelper ;
2828use TYPO3 \CMS \Core \Database \Query \Restriction \DeletedRestriction ;
29- use TYPO3 \CMS \Core \Database \Query \Restriction \HiddenRestriction ;
3029use TYPO3 \CMS \Core \Exception \SiteNotFoundException ;
3130use TYPO3 \CMS \Core \Site \Entity \NullSite ;
3231use TYPO3 \CMS \Core \Site \Entity \Site ;
5453 * pages in the first place - they may not have a page tree und thus no page id at all, like
5554 * for instance the ext:beuser module.
5655 *
57- * Unfortunately, extbase *still* has to calculate *some* TypoScript in any case, even if there
58- * is no page id at all: The default configuration of extbase Backend modules is the "module."
59- * TypoScript setup top-level key. The base config of this is delivered by extbase extensions that
60- * have Backend Modules using ext_typoscript_setup.typoscript, and/or via TYPO3_CONF_VARS TypoScript
61- * setup defaults. Those have to be loaded in any case, even if there is no page at all in the page
62- * tree.
63- *
64- * The code thus has to hop through quite some loops to "find" some relevant page id it can guess
65- * if none is incoming from the request. It even fakes a default sys_template row to trigger
66- * TypoScript loading of globals and ext_typoscript_setup.typoscript if it couldn't find anything.
67- *
6856 * @internal only to be used within Extbase, not part of TYPO3 Core API.
6957 */
7058final readonly class BackendConfigurationManager
@@ -99,9 +87,14 @@ public function getConfiguration(ServerRequestInterface $request, array $configu
9987 $ pluginNameFromConfig = $ configuration ['pluginName ' ] ?? null ;
10088 $ configuration = $ this ->typoScriptService ->convertTypoScriptArrayToPlainArray ($ configuration );
10189
102- $ frameworkConfiguration = $ this ->getExtbaseConfiguration ($ request );
90+ $ typoscriptSetup = $ this ->getTypoScriptSetup ($ request );
91+ $ frameworkConfiguration = [];
92+ if (isset ($ typoscriptSetup ['config. ' ]['tx_extbase. ' ])) {
93+ $ frameworkConfiguration = $ this ->typoScriptService ->convertTypoScriptArrayToPlainArray ($ typoscriptSetup ['config. ' ]['tx_extbase. ' ]);
94+ }
95+
10396 if (!isset ($ frameworkConfiguration ['persistence ' ]['storagePid ' ])) {
104- $ currentPageId = $ this ->getCachedCurrentPageId ($ request );
97+ $ currentPageId = $ this ->getCurrentPageId ($ request );
10598 $ frameworkConfiguration ['persistence ' ]['storagePid ' ] = $ currentPageId ;
10699 }
107100 // only merge $configuration and override controller configuration when retrieving configuration of the current plugin
@@ -145,7 +138,7 @@ public function getConfiguration(ServerRequestInterface $request, array $configu
145138 */
146139 public function getTypoScriptSetup (ServerRequestInterface $ request ): array
147140 {
148- $ currentPageId = $ this ->getCachedCurrentPageId ($ request );
141+ $ currentPageId = $ this ->getCurrentPageId ($ request );
149142
150143 $ cacheIdentifier = 'extbase-backend-typoscript-pageId- ' . $ currentPageId ;
151144 $ setupArray = $ this ->runtimeCache ->get ($ cacheIdentifier );
@@ -174,34 +167,33 @@ public function getTypoScriptSetup(ServerRequestInterface $request): array
174167
175168 $ rootLine = [];
176169 $ sysTemplateRows = [];
177- $ sysTemplateFakeRow = [
178- 'uid ' => 0 ,
179- 'pid ' => 0 ,
180- 'title ' => 'Fake sys_template row to force extension statics loading ' ,
181- 'root ' => 1 ,
182- 'clear ' => 3 ,
183- 'include_static_file ' => '' ,
184- 'basedOn ' => '' ,
185- 'includeStaticAfterBasedOn ' => 0 ,
186- 'static_file_mode ' => false ,
187- 'constants ' => '' ,
188- 'config ' => '' ,
189- 'deleted ' => 0 ,
190- 'hidden ' => 0 ,
191- 'starttime ' => 0 ,
192- 'endtime ' => 0 ,
193- 'sorting ' => 0 ,
194- ];
195170 if ($ currentPageId > 0 ) {
196171 $ rootLine = GeneralUtility::makeInstance (RootlineUtility::class, $ currentPageId )->get ();
197172 $ sysTemplateRows = $ this ->sysTemplateRepository ->getSysTemplateRowsByRootline ($ rootLine , $ request );
198173 ksort ($ rootLine );
199174 }
200-
201175 $ sets = $ site instanceof Site ? $ this ->setRegistry ->getSets (...$ site ->getSets ()) : [];
202176 if (empty ($ sysTemplateRows ) && $ sets === []) {
203- // If there is no page (pid 0 only), or if the first 'is_siteroot' site has no sys_template record or assigned site sets,
204- // then we "fake" a sys_template row: This triggers inclusion of 'global' and 'extension static' TypoScript.
177+ // If no page with sys_template rows or site sets could be derived, we
178+ // "fake" a row to trigger inclusion of 'global' TypoScript only.
179+ $ sysTemplateFakeRow = [
180+ 'uid ' => 0 ,
181+ 'pid ' => 0 ,
182+ 'title ' => 'Fake sys_template row to force global TypoScript loading ' ,
183+ 'root ' => 1 ,
184+ 'clear ' => 3 ,
185+ 'include_static_file ' => '' ,
186+ 'basedOn ' => '' ,
187+ 'includeStaticAfterBasedOn ' => 0 ,
188+ 'static_file_mode ' => false ,
189+ 'constants ' => '' ,
190+ 'config ' => '' ,
191+ 'deleted ' => 0 ,
192+ 'hidden ' => 0 ,
193+ 'starttime ' => 0 ,
194+ 'endtime ' => 0 ,
195+ 'sorting ' => 0 ,
196+ ];
205197 $ sysTemplateRows [] = $ sysTemplateFakeRow ;
206198 }
207199
@@ -220,19 +212,6 @@ public function getTypoScriptSetup(ServerRequestInterface $request): array
220212 return $ setupArray ;
221213 }
222214
223- /**
224- * Returns the TypoScript configuration found in config.tx_extbase
225- */
226- private function getExtbaseConfiguration (ServerRequestInterface $ request ): array
227- {
228- $ setup = $ this ->getTypoScriptSetup ($ request );
229- $ extbaseConfiguration = [];
230- if (isset ($ setup ['config. ' ]['tx_extbase. ' ])) {
231- $ extbaseConfiguration = $ this ->typoScriptService ->convertTypoScriptArrayToPlainArray ($ setup ['config. ' ]['tx_extbase. ' ]);
232- }
233- return $ extbaseConfiguration ;
234- }
235-
236215 /**
237216 * Returns the TypoScript configuration found in module.tx_yourextension_yourmodule
238217 * merged with the global configuration of your extension from module.tx_yourextension
@@ -256,39 +235,10 @@ private function getPluginConfiguration(ServerRequestInterface $request, string
256235 return $ pluginConfiguration ;
257236 }
258237
259- private function getCachedCurrentPageId (ServerRequestInterface $ request ): int
260- {
261- $ currentPageId = $ this ->runtimeCache ->get ('extbase-backend-typoscript-currentPageId ' );
262- if (!is_int ($ currentPageId )) {
263- $ currentPageId = $ this ->getCurrentPageId ($ request );
264- $ this ->runtimeCache ->set ('extbase-backend-typoscript-currentPageId ' , $ currentPageId );
265- }
266- return $ currentPageId ;
267- }
268-
269238 /**
270- * The full madness to guess a page id:
271- * - First try to get one from the request, accessing POST / GET 'id'
272- * - else, fetch the first page in page tree that has 'is_siteroot' set
273- * - else, fetch the first sys_template record that has 'root' flag set, and use its pid
274- * - else, 0, indicating "there are no 'is_siteroot' pages and no sys_template 'root' records"
275- *
276- * @return int current page id. If no page is selected current root page id is returned
239+ * Get page id from the request, accessing POST / GET 'id'
277240 */
278241 private function getCurrentPageId (ServerRequestInterface $ request ): int
279- {
280- $ currentPageId = $ this ->getCurrentPageIdFromRequest ($ request );
281- $ currentPageId = $ currentPageId ?: $ this ->getCurrentPageIdFromCurrentSiteRoot ();
282- $ currentPageId = $ currentPageId ?: $ this ->getCurrentPageIdFromRootTemplate ();
283- return $ currentPageId ?: 0 ;
284- }
285-
286- /**
287- * Gets the current page ID from the GET/POST data.
288- *
289- * @return int the page UID, will be 0 if none has been set
290- */
291- private function getCurrentPageIdFromRequest (ServerRequestInterface $ request ): int
292242 {
293243 // @todo: This misuses 'id' as a broken convention for pages-uid. The filelist module for instance
294244 // uses 'id' as "storage-uid:path", which is only mitigated here by testing the argument
@@ -302,64 +252,6 @@ private function getCurrentPageIdFromRequest(ServerRequestInterface $request): i
302252 return $ id ;
303253 }
304254
305- /**
306- * Gets the current page ID from the first site root in tree.
307- *
308- * @return int the page UID, will be 0 if none has been set
309- */
310- private function getCurrentPageIdFromCurrentSiteRoot (): int
311- {
312- $ queryBuilder = $ this ->connectionPool ->getQueryBuilderForTable ('pages ' );
313- $ queryBuilder ->getRestrictions ()->removeAll ()
314- ->add (GeneralUtility::makeInstance (DeletedRestriction::class))
315- ->add (GeneralUtility::makeInstance (HiddenRestriction::class));
316- $ rootPage = $ queryBuilder
317- ->select ('uid ' )
318- ->from ('pages ' )
319- ->where (
320- $ queryBuilder ->expr ()->eq ('is_siteroot ' , $ queryBuilder ->createNamedParameter (1 , Connection::PARAM_INT )),
321- $ queryBuilder ->expr ()->eq ('sys_language_uid ' , $ queryBuilder ->createNamedParameter (0 , Connection::PARAM_INT )),
322- // Only consider live root page IDs, never return a versioned root page ID
323- $ queryBuilder ->expr ()->eq ('t3ver_oid ' , $ queryBuilder ->createNamedParameter (0 , Connection::PARAM_INT )),
324- $ queryBuilder ->expr ()->eq ('t3ver_wsid ' , $ queryBuilder ->createNamedParameter (0 , Connection::PARAM_INT ))
325- )
326- ->orderBy ('sorting ' )
327- ->setMaxResults (1 )
328- ->executeQuery ()
329- ->fetchAssociative ();
330- if (empty ($ rootPage )) {
331- return 0 ;
332- }
333- return (int )$ rootPage ['uid ' ];
334- }
335-
336- /**
337- * Gets the current page ID from the first created root template.
338- *
339- * @return int the page UID, will be 0 if none has been set
340- */
341- private function getCurrentPageIdFromRootTemplate (): int
342- {
343- $ queryBuilder = $ this ->connectionPool ->getQueryBuilderForTable ('sys_template ' );
344- $ queryBuilder ->getRestrictions ()->removeAll ()
345- ->add (GeneralUtility::makeInstance (DeletedRestriction::class))
346- ->add (GeneralUtility::makeInstance (HiddenRestriction::class));
347- $ rootTemplate = $ queryBuilder
348- ->select ('pid ' )
349- ->from ('sys_template ' )
350- ->where (
351- $ queryBuilder ->expr ()->eq ('root ' , $ queryBuilder ->createNamedParameter (1 , Connection::PARAM_INT ))
352- )
353- ->orderBy ('crdate ' )
354- ->setMaxResults (1 )
355- ->executeQuery ()
356- ->fetchAssociative ();
357- if (empty ($ rootTemplate )) {
358- return 0 ;
359- }
360- return (int )$ rootTemplate ['pid ' ];
361- }
362-
363255 /**
364256 * Returns an array of storagePIDs that are below a list of storage pids.
365257 *
@@ -390,7 +282,6 @@ private function getRecursiveStoragePids(array $storagePids, int $recursionDepth
390282 /**
391283 * Recursively fetch all children of a given page
392284 *
393- * @param int $pid uid of the page
394285 * @return int[] List of child row $uid's
395286 */
396287 private function getPageChildrenRecursive (int $ pid , int $ depth , int $ begin , string $ permsClause ): array
0 commit comments