Skip to content

Commit

Permalink
Switched from PageRenderer to AssetCollector
Browse files Browse the repository at this point in the history
  • Loading branch information
stephankellermayr committed Jun 24, 2024
1 parent 0844b83 commit e98e5d8
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 59 deletions.
5 changes: 0 additions & 5 deletions Classes/Form/Element/IconpackWizardElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ public function render(): array
// Add inline labels
$pageRenderer->addInlineLanguageLabelFile('EXT:iconpack/Resources/Private/Language/locallang_be.xlf', 'js.');

$cssFiles = $this->iconpackFactory->queryAssets('css', 'backend');
foreach ($cssFiles as $cssFile) {
$pageRenderer->addCssFile($cssFile);
}

$languageService = $this->getLanguageService();
$parameterArray = $this->data['parameterArray'];
$itemName = $parameterArray['itemFormElName'];
Expand Down
61 changes: 61 additions & 0 deletions Classes/Hooks/AssetRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace Quellenform\Iconpack\Hooks;

/*
* This file is part of the "iconpack" Extension for TYPO3 CMS.
*
* Conceived and written by Stephan Kellermayr
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

use Psr\Http\Message\ServerRequestInterface;
use Quellenform\Iconpack\IconpackFactory;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Page\AssetCollector;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* AssetRenderer hook to add iconpack assets for FE/BE calls
*
* @internal This is a specific hook implementation and is not considered part of the Public TYPO3 API.
*/
final class AssetRenderer
{

public function addCss()
{
if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface) {
/** @var IconpackFactory $iconpackFactory */
$iconpackFactory = GeneralUtility::makeInstance(IconpackFactory::class);

/** @var AssetCollector $assetCollector */
$assetCollector = GeneralUtility::makeInstance(AssetCollector::class);

$styleSheets = [];
if (
ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend() &&
(bool) \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class
)->get('iconpack', 'autoAddAssets')
) {
$styleSheets = $iconpackFactory->queryAssets('css', 'frontend');
} elseif (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) {
$styleSheets = $iconpackFactory->queryAssets('css', 'backend');
}
// Add StyleSheets
foreach ($styleSheets as $key => $styleSheet) {
// @extensionScannerIgnoreLine
$assetCollector->addStyleSheet(
'iconpack_' . $key,
$styleSheet,
['media' => 'all']
);
}
}
}
}
44 changes: 0 additions & 44 deletions Classes/Hooks/PageRendererHook.php

This file was deleted.

4 changes: 4 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@
$GLOBALS['TYPO3_CONF_VARS']['BE']['stylesheets']['iconpack']
= 'EXT:iconpack/Resources/Public/Css/Backend/FormEngine/IconpackWizard.min.css';
}

// Hook to add iconpack assets to the AssetsCollector in the FE/BE:
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess']['quellenform/assetcollector']
= \Quellenform\Iconpack\Hooks\AssetRenderer::class . '->addCss';
});
10 changes: 0 additions & 10 deletions ext_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@

defined('TYPO3') || die();

// Hook to add iconpack assets to the PageRenderer in the frontend:
if (
(bool) \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class
)->get('iconpack', 'autoAddAssets')
) {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'][]
= \Quellenform\Iconpack\Hooks\PageRendererHook::class . '->addIconpackAssets';
}

if (version_compare(TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '12.3.0', '<')) {
// https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.3/Deprecation-100232-TBE_STYLESSkinningFunctionality.html
// @extensionScannerIgnoreLine
Expand Down

0 comments on commit e98e5d8

Please sign in to comment.