mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-01 14:30:32 +02:00
[ticket/17291] Default to fa-solid if classes are set without fa class
PHPBB3-17291
This commit is contained in:
@@ -83,7 +83,7 @@ class icon extends AbstractExtension
|
||||
switch ($type)
|
||||
{
|
||||
case 'font':
|
||||
// Nothing to do here..
|
||||
$classes = $this->insert_fa_class($classes);
|
||||
break;
|
||||
|
||||
case 'png':
|
||||
@@ -168,6 +168,39 @@ class icon extends AbstractExtension
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert fa class into class string by checking if class string contains any fa classes
|
||||
*
|
||||
* @param string $class_string
|
||||
* @return string Updated class string or original class string if fa class is already set or string is empty
|
||||
*/
|
||||
protected function insert_fa_class(string $class_string): string
|
||||
{
|
||||
if (empty($class_string))
|
||||
{
|
||||
return $class_string;
|
||||
}
|
||||
|
||||
// These also include pro class name we don't use, but handle them properly anyway
|
||||
$fa_classes = ['fa-solid', 'fas', 'fa-regular', 'far', 'fal', 'fa-light', 'fab', 'fa-brands'];
|
||||
|
||||
// Split the class string into individual words
|
||||
$icon_classes = explode(' ', $class_string);
|
||||
|
||||
// Check if the class string contains any of the fa classes, just return class string in that case
|
||||
foreach ($icon_classes as $word)
|
||||
{
|
||||
if (in_array($word, $fa_classes))
|
||||
{
|
||||
return $class_string;
|
||||
}
|
||||
}
|
||||
|
||||
// If we reach this it means we didn't have any fa classes in the class string.
|
||||
// Prepend class string with fas for fa-solid
|
||||
return 'fas ' . $class_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare an SVG for usage in the template icon.
|
||||
*
|
||||
|
Reference in New Issue
Block a user