From ab9ac19c47a199e82c26a0c511a59b1f015af708 Mon Sep 17 00:00:00 2001 From: Nikita Hovratov Date: Thu, 29 Aug 2024 20:26:19 +0200 Subject: [PATCH] [BUGFIX] Use BootCompletedEvent to register icons In TYPO3 v13 it's still not possible to use the more appropriate extension method to register icons, because extension can instantiate IconRegistry inside ext_localconf.php files. This is now deprecated in v13 and we can switch to the extension method in TYPO3 v14. Fixes: #215 (cherry picked from commit 1db5b5c83070f56e75fb327691513ce0480adcc3) --- Classes/ServiceProvider.php | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Classes/ServiceProvider.php b/Classes/ServiceProvider.php index 52c51d6c..ba74f7ac 100644 --- a/Classes/ServiceProvider.php +++ b/Classes/ServiceProvider.php @@ -69,6 +69,7 @@ public function getFactories(): array 'content-blocks.parent-field-names' => static::getContentBlockParentFieldNames(...), 'content-blocks.add-typoscript' => static::addTypoScript(...), 'content-blocks.add-user-tsconfig' => static::addUserTsConfig(...), + 'content-blocks.register-icons' => static::configureIconRegistry(...), 'content-blocks.hide-content-element-children' => static::hideContentElementChildren(...), 'content-blocks.record-summary-for-localization' => static::recordSummaryForLocalization(...), 'content-blocks.base-simple-tca-schema' => static::baseSimpleTcaSchema(...), @@ -79,7 +80,6 @@ public function getFactories(): array public function getExtensions(): array { return [ - IconRegistry::class => static::configureIconRegistry(...), PageDoktypeRegistry::class => static::configurePageTypes(...), ListenerProvider::class => static::addEventListeners(...), ] + parent::getExtensions(); @@ -329,22 +329,24 @@ public static function recordSummaryForLocalization(ContainerInterface $containe }; } - public static function configureIconRegistry(ContainerInterface $container, IconRegistry $iconRegistry): IconRegistry + public static function configureIconRegistry(ContainerInterface $container): \Closure { - $iconsFromPackages = $container->get('content-blocks.icons'); - foreach ($iconsFromPackages as $icon => $options) { - $provider = $options['provider'] ?? null; - unset($options['provider']); - $options ??= []; - if ($provider === null && ($options['source'] ?? false)) { - $provider = $iconRegistry->detectIconProvider($options['source']); - } - if ($provider === null) { - continue; + return static function (BootCompletedEvent $event) use ($container) { + $iconRegistry = $container->get(IconRegistry::class); + $iconsFromPackages = $container->get('content-blocks.icons'); + foreach ($iconsFromPackages as $icon => $options) { + $provider = $options['provider'] ?? null; + unset($options['provider']); + $options ??= []; + if ($provider === null && ($options['source'] ?? false)) { + $provider = $iconRegistry->detectIconProvider($options['source']); + } + if ($provider === null) { + continue; + } + $iconRegistry->registerIcon($icon, $provider, $options); } - $iconRegistry->registerIcon($icon, $provider, $options); - } - return $iconRegistry; + }; } public static function configurePageTypes(ContainerInterface $container, PageDoktypeRegistry $pageDoktypeRegistry): PageDoktypeRegistry @@ -365,6 +367,7 @@ public static function configurePageTypes(ContainerInterface $container, PageDok public static function addEventListeners(ContainerInterface $container, ListenerProvider $listenerProvider): ListenerProvider { $listenerProvider->addListener(BootCompletedEvent::class, 'content-blocks.add-typoscript'); + $listenerProvider->addListener(BootCompletedEvent::class, 'content-blocks.register-icons'); $listenerProvider->addListener(BeforeLoadedUserTsConfigEvent::class, 'content-blocks.add-user-tsconfig'); $listenerProvider->addListener(ModifyDatabaseQueryForContentEvent::class, 'content-blocks.hide-content-element-children'); $listenerProvider->addListener(AfterRecordSummaryForLocalizationEvent::class, 'content-blocks.record-summary-for-localization');