Skip to content

Commit

Permalink
Added ability to choose between FontAwesome versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Anderson committed Jan 1, 2018
1 parent 88e7294 commit 54e54bd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
Empty file modified LICENSE.txt
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion config/font_awesome.settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"_config_name": "font_awesome.settings",
"enabled": false
"fontawesome": "v5"
}

15 changes: 10 additions & 5 deletions font_awesome.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
* Form constructor for the Font Awesome settings form.
*/
function font_awesome_admin_form($form, &$form_state) {
$form['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Use Font Awesome icons in your website'),
'#description' => t('This will load the necessary CSS for you to start adding icons to your site. See <a href="http://fontawesome.io/examples/">http://fontawesome.io/examples/</a> for examples.'),
'#default_value' => config_get('font_awesome.settings', 'enabled'),
$form['fontawesome'] = array(
'#type' => 'radios',
'#title' => t('Enable Font Awesome icons'),
'#description' => t('Load the necessary FontAwesome CSS/JS. See the provided links for examples of how to actualy add icons.'),
'#options' => array(
'' => t('Disabled'),
'v4' => t('v4 (<a href="http://fontawesome.io/examples/" target="_blank">fontawesome.io</a>)'),
'v5' => t('v5 (<a href="https://fontawesome.com/how-to-use/svg-with-js" target="_blank">fontawesome.com</a>)'),
),
'#default_value' => config_get('font_awesome.settings', 'fontawesome'),
);

$form['#config'] = 'font_awesome.settings';
Expand Down
16 changes: 16 additions & 0 deletions font_awesome.install
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
* Install, update, and uninstall functions for the Font Awesome module.
*/

/**
* Implements hook_update_N().
*/
function font_awesome_update_1100(&$sandbox) {
// Update config.
$config = config('font_awesome.settings');
if ($config->get('enabled') == TRUE) {
$config->set('fontawesome', 'v4');
}
else {
$config->set('fontawesome', '');
}
$config->clear('enabled');
$config->save();
}

/**
* Implements hook_update_N().
*/
Expand Down
17 changes: 12 additions & 5 deletions font_awesome.module
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ function font_awesome_config_info() {
* Implements hook_init().
*/
function font_awesome_init() {
if (config_get('font_awesome.settings', 'enabled')) {
backdrop_add_css('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css', array(
'type' => 'external',
'every_page' => TRUE,
));
$options = array(
'type' => 'external',
'every_page' => TRUE,
);

switch (config_get('font_awesome.settings', 'fontawesome')) {
case 'v4':
backdrop_add_css('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css', $options);
break;
case 'v5':
backdrop_add_js('https://use.fontawesome.com/releases/v5.0.2/js/all.js', $options);
break;
}
}

Expand Down

0 comments on commit 54e54bd

Please sign in to comment.