Skip to content

Commit

Permalink
[BUGFIX] Use BootCompletedEvent to register icons
Browse files Browse the repository at this point in the history
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 1db5b5c)
  • Loading branch information
nhovratov committed Aug 29, 2024
1 parent e071107 commit ab9ac19
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions Classes/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(...),
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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');
Expand Down

0 comments on commit ab9ac19

Please sign in to comment.