<?php
declare(strict_types=1);
namespace B13\Assetcollector\Hooks\PageRenderer;
use B13\Assetcollector\AssetCollector;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
/**
* PostProcessHook, this is referenced in ext_localconf.php
* and should be executed once after all page rendering
*/
class PostProcessHook
{
/**
* @param array $params The already used JS and CSS files and the header and footer data
* @param PageRenderer $pageRenderer The back reference to the TYPO3\CMS\Core\Page\PageRenderer class
*/
public function execute(array &$params, PageRenderer &$pageRenderer): void
{
if (!($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface ||
!ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()) {
return;
}
$assetCollector = GeneralUtility::makeInstance(AssetCollector::class);
// seems always empty, solution will follow
// $cached = $this->getTypoScriptFrontendController()->config['b13/assetcollector'] ?? [];
// if (!empty($cached['xmlFiles'] ?? null) && is_array($cached['xmlFiles'])) {
// $assetCollector->mergeXmlFiles($cached['xmlFiles']);
// }
$svgReferences = $assetCollector->buildInlineXmlTag();
$pageRenderer->addFooterData('<!-- SVG asset renderer -->' . PHP_EOL . $svgReferences);
// not working with INT objects...
// $params['bodyContent'] = $params['bodyContent'] . '<!-- SVG asset renderer -->' . PHP_EOL . $svgReferences;
}
// not used, see WIP comment above
protected function getTypoScriptFrontendController(): ?TypoScriptFrontendController
{
return $GLOBALS['TSFE'] ?? null;
}
}
Maybe you can check this solution?
I'm working on a solution for the "set SVG defs via TypoScript", too.
Steps to reproduce:
My solution: I've completely removed the InlineSvgInjector Middleware, and added the SVG asset collector as footer data:
in _extlocalconf.php add:
add Classes/Hooks/PageRenderer/PostProcessHook.php :
Maybe you can check this solution?
I'm working on a solution for the "set SVG defs via TypoScript", too.
Best regards Matthias