Skip to content

Commit

Permalink
[BUGFIX] SVG Rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
achimfritz-b13 committed May 24, 2024
1 parent 2e1699c commit a807106
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Build/phpstan11.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ parameters:
- %currentWorkingDirectory%/Classes
excludePaths:
- %currentWorkingDirectory%/Classes/Listener/AfterCacheableContentIsGenerated.php
ignoreErrors:
- '#.*unknown class TYPO3\\CMS\\Core\\TypoScript\\FrontendTypoScript.#'
25 changes: 22 additions & 3 deletions Classes/AssetCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
*/

use B13\Assetcollector\Resource\ResourceCompressor;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
Expand Down Expand Up @@ -218,6 +220,7 @@ public function buildInlineXmlTag(): string
. '</symbol>';
}
}

if (trim($inlineXml) !== '') {
return '<svg class="tx_assetcollector" aria-hidden="true" style="display: none;" version="1.1" xmlns="http://www.w3.org/2000/svg" '
. 'xmlns:xlink="http://www.w3.org/1999/xlink">'
Expand Down Expand Up @@ -255,12 +258,28 @@ public function getTypoScriptValue(string $name): string
protected function loadTypoScript(): void
{
$this->typoScriptConfiguration = [];
$frontendController = $this->getTypoScriptFrontendController();
if ($frontendController !== null) {
$this->typoScriptConfiguration = $frontendController->tmpl->setup['plugin.']['tx_assetcollector.']['icons.'] ?? [];
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 12) {
$frontendController = $this->getTypoScriptFrontendController();
if ($frontendController !== null) {
$this->typoScriptConfiguration = $frontendController->tmpl->setup['plugin.']['tx_assetcollector.']['icons.'] ?? [];
}
} else {
$request = $this->getServerRequest();
if ($request === null) {
return;
}
/** @var FrontendTypoScript $typoScript */
$typoScript = $request->getAttribute('frontend.typoscript');
$setup = $typoScript->getSetupArray();
$this->typoScriptConfiguration = $setup['plugin.']['tx_assetcollector.']['icons.'] ?? [];
}
}

protected function getServerRequest(): ?ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'] ?? null;
}

protected function getTypoScriptFrontendController(): ?TypoScriptFrontendController
{
if (($GLOBALS['TSFE'] ?? null) instanceof TypoScriptFrontendController) {
Expand Down
11 changes: 11 additions & 0 deletions Tests/Functional/Frontend/Fixtures/SvgViewHelper.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"pages"
,"uid","pid","title","slug"
,1,0,"root","/"
"sys_template"
,"uid","pid","root","config"
,1,1,1,"page = PAGE
page.10 = FLUIDTEMPLATE
page.10.templateRootPaths.10 = EXT:assetcollector/Tests/Functional/Frontend/Fixtures/Templates
page.10.templateName = SvgViewHelper.html
plugin.tx_assetcollector.icons.download = EXT:assetcollector/Resources/Public/Icons/Extension.svg
"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:ac="http://typo3.org/ns/B13/Assetcollector/ViewHelpers"
data-namespace-typo3-fluid="true"
>
<f:spaceless>
<ac:svg name="download" />
</f:spaceless>
</html>
37 changes: 37 additions & 0 deletions Tests/Functional/Frontend/SvgViewHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace B13\Assetcollector\Tests\Functional\Functional;

/*
* This file is part of TYPO3 CMS-based extension "assetcollector" by b13.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/

use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class SvgViewHelperTest extends FunctionalTestCase
{
protected array $testExtensionsToLoad = ['typo3conf/ext/assetcollector'];
protected array $coreExtensionsToLoad = ['core', 'frontend'];
protected array $pathsToLinkInTestInstance = ['typo3conf/ext/assetcollector/Build/sites' => 'typo3conf/sites'];

/**
* @test
*/
public function scriptTagForInlineCssIsRendered(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/SvgViewHelper.csv');
$response = $this->executeFrontendSubRequest(new InternalRequest('http://localhost/'));
$expected = '<svg><use xlink:href="#icon-Extension"></use></svg>';
$body = (string)$response->getBody();
self::assertStringContainsString($expected, $body);
$expected = '<svg class="tx_assetcollector"';
self::assertStringContainsString($expected, $body);
$expected = '<rect y="0.3" class="st0" width="256" height="256"></rect>';
self::assertStringContainsString($expected, $body);
}
}

0 comments on commit a807106

Please sign in to comment.