mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 13:28:55 +00:00
[ticket/17291] Default to fa-solid if classes are set without fa class
PHPBB3-17291
This commit is contained in:
parent
511d96a522
commit
ddb4f142a6
2 changed files with 35 additions and 2 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -313,7 +313,7 @@ class phpbb_template_extension_test extends phpbb_template_template_test_case
|
|||
[
|
||||
'ICON_PENCIL' => 'Pencil icon',
|
||||
],
|
||||
'<i class="o-icon o-icon-font fa-fw fa-pencil a-class another-class" title="Pencil icon" aria-hidden="true" data-attr-1="true" data-attr-2="two"></i>
|
||||
'<i class="o-icon o-icon-font fa-fw fa-pencil fas a-class another-class" title="Pencil icon" aria-hidden="true" data-attr-1="true" data-attr-2="two"></i>
|
||||
<span class="sr-only">Pencil icon</span>'
|
||||
],
|
||||
/** Font: icons array */
|
||||
|
|
Loading…
Add table
Reference in a new issue