Skip to content
Snippets Groups Projects

Maps the old-style Font Awesome prefixes to the new Font Awesome 6.x format.

@@ -183,7 +183,7 @@ class FontAwesomeIconFormatter extends FormatterBase implements ContainerFactory
'#tag' => $configurationSettings->get('tag'),
'#iconset' => $iconset,
'#name' => 'fa-' . $item->get('icon_name')->getValue(),
'#style' => $item->get('style')->getValue(),
'#style' => $this->mapStylePrefix($item->get('style')->getValue()),
'#settings' => implode(' ', array_filter($iconSettings)),
'#transforms' => implode(' ', $iconTransforms),
'#mask' => $iconMask,
@@ -203,4 +203,29 @@ class FontAwesomeIconFormatter extends FormatterBase implements ContainerFactory
];
}
/**
* Converts old Font Awesome style prefixes to the 6.x format.
*
* @param string $style
* The style value from the database.
*
* @return string
* The corrected style value.
*/
private function mapStylePrefix(string $style): string {
if (empty($style)) {
return 'fa-solid';
}
$style_mapping = [
'fa-fas' => 'fa-solid',
'fa-far' => 'fa-regular',
'fa-fab' => 'fa-brands',
'fa-fal' => 'fa-light',
'fa-fad' => 'fa-duotone',
'fa-fat' => 'fa-thin',
];
return $style_mapping[$style] ?? $style;
}
}
Loading