getAttribute('route'); $packageNameFromRoute = $route->getOption('packageName'); if (!empty($packageNameFromRoute)) { $packageNames[] = $packageNameFromRoute; } } // Always add EXT:backend/Resources/Private/ as first default path to resolve // default Layouts/Module.fluid.html and its partials. if (!in_array('typo3/cms-backend', $packageNames, true)) { array_unshift($packageNames, 'typo3/cms-backend'); } // @todo: This assumes the pageId is *always* given as 'id' in request. // @todo: It would be cool if a middleware adds final pageTS - already overlayed by userTS - as attribute to request, to use it here. $pageTs = []; $pageId = $request->getParsedBody()['id'] ?? $request->getQueryParams()['id'] ?? 0; if (MathUtility::canBeInterpretedAsInteger($pageId)) { // Some BE controllers misuse the 'id' argument for something else than the page-uid (especially filelist module). // We check if 'id' is an integer here to skip pageTsConfig calculation if that is the case. // @todo: Mid-term, misuses should vanish, making 'id' a Backend convention. Affected is // at least ext:filelist, plus record linking modals that use 'pid'. $pageTs = BackendUtility::getPagesTSconfig((int)$pageId); } $templatePaths = [ 'templateRootPaths' => [], 'layoutRootPaths' => [], 'partialRootPaths' => [], ]; foreach ($packageNames as $packageName) { // Add paths for package. $packagePath = $this->packageManager->getPackage($packageName)->getPackagePath(); $templatePaths['templateRootPaths'][] = $packagePath . 'Resources/Private/Templates'; $templatePaths['layoutRootPaths'][] = $packagePath . 'Resources/Private/Layouts'; $templatePaths['partialRootPaths'][] = $packagePath . 'Resources/Private/Partials'; // Add possible overrides. if (is_array($pageTs['templates.'][$packageName . '.'] ?? false)) { $overrides = $pageTs['templates.'][$packageName . '.']; ksort($overrides); foreach ($overrides as $override) { $pathParts = GeneralUtility::trimExplode(':', $override, true); if (count($pathParts) < 2) { throw new \RuntimeException( 'When overriding template paths, the syntax is "composer-package-name:path", example: "typo3/cms-seo:Resources/Private/TemplateOverrides/typo3/cms-backend"', 1643798660 ); } $composerPackageName = $pathParts[0]; $overridePackagePath = $this->packageManager->getPackage($composerPackageName)->getPackagePath(); $overridePath = rtrim($pathParts[1], '/'); $templatePaths['templateRootPaths'][] = $overridePackagePath . $overridePath . '/Templates'; $templatePaths['layoutRootPaths'][] = $overridePackagePath . $overridePath . '/Layouts'; $templatePaths['partialRootPaths'][] = $overridePackagePath . $overridePath . '/Partials'; } } } // @todo: Inject ViewFactoryInterface instead, and use it. $renderingContext = $this->renderingContextFactory->create($templatePaths, $request); $fluidView = new FluidTemplateView($renderingContext); return new FluidViewAdapter($fluidView); } }