How to upgrade Font Awesome from 4.7 to 5.0 in Moodle 3.5?

How to upgrade Font Awesome from 4.7 to 5.0 in Moodle 3.5?

by Visvanath Ratnaweera -
Number of replies: 8
Picture of Particularly helpful Moodlers Picture of Translators
What is the procedure to upgrade Font Awesome from 4.7.0 to 5.0 Free Icons in Moodle 3.5? Theme is Classic, if it matters.
Average of ratings: -
In reply to Visvanath Ratnaweera

Re: How to upgrade Font Awesome from 4.7 to 5.0 in Moodle 3.5?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
Procedure no, code yes but in terms of being in the Shoelace theme. Also the Moove theme has custom icon font serving but its incomplete.
In reply to Gareth J Barnard

Re: How to upgrade Font Awesome from 4.7 to 5.0 in Moodle 3.5?

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Hi Gareth

Thanks for the reply. I understand it as take Moodle 3.7 if I don't want to touch the Moodle code.

What it I don't mind touching the Moodle (3.5) code? The theme remains at Classic.
In reply to Visvanath Ratnaweera

Re: How to upgrade Font Awesome from 4.7 to 5.0 in Moodle 3.5?

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

The code is in Shoelace for Moodle 3.6 and all contained within the theme, so a implementing in a child theme of Classic is possible.

In reply to Gareth J Barnard

Re: How to upgrade Font Awesome from 4.7 to 5.0 in Moodle 3.5? [CLOSED]

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Hi Gareth

Thanks for all the explanations. I consider creating a child theme for the interim period, until we upgrade to 3.7 or higher, is too much. So the matter is closed.
In reply to Visvanath Ratnaweera

Re: How to upgrade Font Awesome from 4.7 to 5.0 in Moodle 3.5? [CLOSED]

by Lexy Walker -
Picture of Core developers Picture of Particularly helpful Moodlers
I know I'm a month late to this party, but I have a little bit of input on this.

I looked into doing this in my Boost-based theme, but decided against it after I'd done about 10% of the work.

Although FontAwesome 5 has a lot of new icons, there are some icons that used to be free that are now paid-only - particularly the old 'outline' icons. It was going to be a lot of work to change all the icon names that have been changed, and replace the couple of icons Moodle uses that are no longer included in the free version. I had more important things to do.

You can do this without changing core code. All you'd need to do is include the newer version of FontAwesome in your theme, then override the icon rendering class by including a theme/yourthemename/classes/output/icon_system_fontawesome.php file in your theme.

You can find the default icon_system_fontawesome.php file lib/classes/output/ folder. It's just a mapping of Moodle's internal icon codes, and which FontAwesome icon classes should be used for each one.

You don't need to re-declare all the built-in icons in your custom file. In fact, I wouldn't recommend it, in case the underlying core icons change. You can do something like this t override the icons you want, and add them on top of the core ones:

namespace theme_yourtheme\output;
use renderer_base;
use pix_icon;
defined('MOODLE_INTERNAL') || die();
class icon_system_fontawesome extends \core\output\icon_system_fontawesome {
 
    public function get_core_icon_map() {
        $iconmap = parent::get_core_icon_map();
        
        $overrides = Array(
            'core:req'                          => 'fa-asterisk text-warning',
            'core:i/section'                    => 'fa-folder-open',
            'theme:hillhead/allcourses'          => 'fa-sitemap',
            'theme:hillhead/starred'             => 'fa-star',
            'theme:hillhead/vleenhancements'     => 'fa-magic',
            'theme:hillhead/role'                => 'fa-key'
        );
        
        $merged = array_merge($iconmap, $overrides);
        
        return $merged;
    }
}
public function get_icon_name_map() {
    if ($this->map === []) {
        $cache = \cache::make('theme_hillhead', 'fontawesomeiconmapping');

        $this->map = $cache->get('mapping');

        if (empty($this->map)) {
            $this->map = $this->get_core_icon_map();
            $callback = 'get_fontawesome_icon_map';

            if ($pluginsfunction = get_plugins_with_function($callback)) {
                foreach ($pluginsfunction as $plugintype => $plugins) {
                    foreach ($plugins as $pluginfunction) {
                        $pluginmap = $pluginfunction();
                        $this->map += $pluginmap;
                    }
                }
            }
            $cache->set('mapping', $this->map);
        }

    }
    return $this->map;
}


Average of ratings: Useful (1)
In reply to Lexy Walker

Re: How to upgrade FontAwesome from 4.7 to 5.0 in Moodle 3.5? [REOPENED]

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Hi

What a coincidence! Although the subject was put to rest I was going through a new wave of requests from my users for FontAwesome 5.0 (in Moodle 3.5). And to meet the "Spare Howard" on this topic is funny.
smile

A collegue is looking in to this. I am not too much moved by all these. After all, Goethe and Schiller scribed all their treasures with 26 "icons". For our work 700+ icons should be sufficient.
In reply to Visvanath Ratnaweera

Re: How to upgrade FontAwesome from 4.7 to 5.0 in Moodle 3.5? [REOPENED]

by Lexy Walker -
Picture of Core developers Picture of Particularly helpful Moodlers

One last detail - the code I provided generates a new cache to store the icon mapping. Don't forget to set it up in theme/whatever/db/caches.php or you'll manage to take your entire site down.

$definitions = array(
    'fontawesomeiconmapping' => array(
        'mode' => cache_store::MODE_APPLICATION,
        'simplekeys' => true,
        'simpledata' => true,
        'staticacceleration' => true,
        'staticaccelerationsize' => 1
    ),
);

Also, as a bonus, this line in my example replaces the red exclamation marks next to required fields with orange stars instead:

'core:req' => 'fa-asterisk text-warning',

In reply to Lexy Walker

Re: How to upgrade FontAwesome from 4.7 to 5.0 in Moodle 3.5? [REOPENED]

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
Hi Lexy,

Also you need to implement a web service for the JS element of fetching the icons.

And with "It was going to be a lot of work to change all the icon names that have been changed, and replace the couple of icons Moodle uses that are no longer included in the free version." - I've already done this as FA provided a 'conversion script' that I've adapted.

My complete solution can be found in my Foundation theme.

Gareth
Average of ratings: Useful (1)