setLanguage($languageService->getLocale(), $request); $pageRenderer->setMetaTag('name', 'viewport', 'width=device-width, initial-scale=1'); $pageRenderer->setFavIcon($this->getBackendFavicon($extensionConfiguration, $request)); $nonce = $request->getAttribute('nonce'); if ($nonce !== null) { $pageRenderer->setNonce($nonce); $pageRenderer->setApplyNonceHint(true); } $this->loadStylesheets($pageRenderer); } /** * Load all registered stylesheets from $GLOBALS['TYPO3_CONF_VARS']['BE']['stylesheets'] */ protected function loadStylesheets(PageRenderer $pageRenderer): void { // @todo this needs to be replaced with usage of the yet to be created // System Resource API that can handle folders // This will then remove the need to use internal SystemResourceIdentifierFactory here $packageManager = GeneralUtility::makeInstance(PackageManager::class); $identifierFactory = new SystemResourceIdentifierFactory($packageManager); foreach ($GLOBALS['TYPO3_CONF_VARS']['BE']['stylesheets'] ?? [] as $potentialResourceIdentifier) { try { $resourceIdentifier = $identifierFactory->create($potentialResourceIdentifier); } catch (InvalidSystemResourceIdentifierException) { continue; } if (!$resourceIdentifier instanceof PackageResourceIdentifier) { continue; } $package = $resourceIdentifier->getPackage(); $relativePath = $resourceIdentifier->getRelativePath(); $absolutePath = $package->getPackagePath() . $relativePath; if (is_dir($absolutePath)) { // Path like 'PKG:vendor/my-extension:Resources/Public/Css/Backend' foreach (GeneralUtility::getFilesInDir($absolutePath, 'css') as $cssFile) { $pageRenderer->addCssFile((string)$resourceIdentifier->withRelativePath(rtrim($relativePath, '/') . '/' . $cssFile)); } } elseif (file_exists($absolutePath)) { // A single file 'PKG:my_extension:Resources/Public/Css/Backend/main.css' or just a single file $pageRenderer->addCssFile((string)$resourceIdentifier); } } } /** * Retrieves configured favicon for backend with fallback. */ protected function getBackendFavicon(ExtensionConfiguration $extensionConfiguration, ServerRequestInterface $request): string { $backendFavicon = $extensionConfiguration->get('backend', 'backendFavicon'); if (!empty($backendFavicon)) { return $this->getUriForFileName($request, $backendFavicon); } return $this->getUriForFileName($request, 'EXT:backend/Resources/Public/Icons/favicon.ico'); } /** * Returns the uri for a system resource * * @throws CanNotResolvePublicResourceException * @throws CanNotResolveSystemResourceException */ protected function getUriForFileName(ServerRequestInterface $request, string $resourceIdentifier): string { return (string)PathUtility::getSystemResourceUri($resourceIdentifier, $request); } }