Skip to content

Commit 01c38fb

Browse files
Merge pull request #20 from bugfolder/15_add_v4_shim_1
Issue #15: Add v4 shims option with v5 FontAwesome.
2 parents 2887581 + ca98c17 commit 01c38fb

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

config/font_awesome.settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"_config_name": "font_awesome.settings",
3-
"fontawesome": "v5"
3+
"fontawesome": "v5",
4+
"v4_shims": 0
45
}
56

font_awesome.admin.inc

+17-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
* Form constructor for the Font Awesome settings form.
99
*/
1010
function font_awesome_admin_form($form, &$form_state) {
11+
$form['#config'] = 'font_awesome.settings';
12+
$config = config('font_awesome.settings');
13+
1114
$form['fontawesome'] = array(
1215
'#type' => 'radios',
1316
'#title' => t('Enable Font Awesome icons'),
@@ -18,10 +21,21 @@ function font_awesome_admin_form($form, &$form_state) {
1821
'v5' => t('<a href="https://fontawesome.com/how-to-use/on-the-web/referencing-icons/basic-use" target="_blank">v5.2</a>'),
1922
'v5.15' => t('<a href="https://fontawesome.com/how-to-use/on-the-web/referencing-icons/basic-use" target="_blank">v5.15</a>'),
2023
),
21-
'#default_value' => config_get('font_awesome.settings', 'fontawesome'),
24+
'#default_value' => $config->get('fontawesome'),
25+
);
26+
27+
$form['v4_shims'] = array(
28+
'#type' => 'checkbox',
29+
'#title' => t('Include v4 shims'),
30+
'#description' => t('Checking this box will allow you to use FontAwesome v4 icon names with FontAwesome v5. <a href="https://fontawesome.com/v5.15/how-to-use/graphql-api/objects/shim" target="_blank">Details here.</a>'),
31+
'#default_value' => $config->get('v4_shims'),
32+
'#states' => array(
33+
'visible' => array(
34+
array(':input[name="fontawesome"]' => array('value' => 'v5')),
35+
array(':input[name="fontawesome"]' => array('value' => 'v5.15')),
36+
),
37+
),
2238
);
2339

24-
$form['#config'] = 'font_awesome.settings';
2540
return system_settings_form($form);
2641
}
27-

font_awesome.install

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
* Install, update, and uninstall functions for the Font Awesome module.
55
*/
66

7+
/**
8+
* Add v4_shim option to settings and initialize.
9+
*/
10+
function font_awesome_update_1102(&$sandbox) {
11+
$config = config('font_awesome.settings');
12+
$config->set('v4_shim', 0);
13+
$config->save();
14+
}
15+
716
/**
817
* Remove 'pseudo' config value.
918
*/
@@ -42,4 +51,3 @@ function font_awesome_update_1001(&$sandbox) {
4251
function font_awesome_update_last_removed() {
4352
return 1000;
4453
}
45-

font_awesome.module

+8
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,19 @@ function font_awesome_init() {
2929
case 'v4':
3030
backdrop_add_css('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css', $options);
3131
break;
32+
3233
case 'v5':
3334
backdrop_add_css('https://use.fontawesome.com/releases/v5.2.0/css/all.css', $options);
35+
if (config_get('font_awesome.settings', 'v4_shims')) {
36+
backdrop_add_css('https://use.fontawesome.com/releases/v5.2.0/css/v4-shims.css', $options);
37+
}
3438
break;
39+
3540
case 'v5.15':
3641
backdrop_add_css('https://use.fontawesome.com/releases/v5.15.4/css/all.css', $options);
42+
if (config_get('font_awesome.settings', 'v4_shims')) {
43+
backdrop_add_css('https://use.fontawesome.com/releases/v5.15.4/css/v4-shims.css', $options);
44+
}
3745
break;
3846
}
3947
}

0 commit comments

Comments
 (0)