-
Notifications
You must be signed in to change notification settings - Fork 5
/
font_awesome.module
117 lines (106 loc) · 3.27 KB
/
font_awesome.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* @file
* Include Font Awesome icons via CSS classes in your website.
*/
/**
* Implements hook_config_info().
*/
function font_awesome_config_info() {
return array(
'font_awesome.settings' => array(
'label' => t('Font Awesome settings'),
'group' => t('Configuration'),
),
);
}
/**
* Implements hook_init().
*/
function font_awesome_init() {
// Add FontAwesome CSS.
$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_css('https://use.fontawesome.com/releases/v5.2.0/css/all.css', $options);
if (config_get('font_awesome.settings', 'v4_shims')) {
backdrop_add_css('https://use.fontawesome.com/releases/v5.2.0/css/v4-shims.css', $options);
}
break;
case 'v5.15':
backdrop_add_css('https://use.fontawesome.com/releases/v5.15.4/css/all.css', $options);
if (config_get('font_awesome.settings', 'v4_shims')) {
backdrop_add_css('https://use.fontawesome.com/releases/v5.15.4/css/v4-shims.css', $options);
}
break;
case 'v6.4':
backdrop_add_css('https://use.fontawesome.com/releases/v6.4.2/css/all.css', $options);
if (config_get('font_awesome.settings', 'v4_shims')) {
backdrop_add_css('https://use.fontawesome.com/releases/v6.4.2/css/v4-shims.css', $options);
}
break;
case 'local':
$options = array(
'every_page' => TRUE,
);
backdrop_add_css(config_get('font_awesome.settings', 'local_path'), $options);
break;
case 'other':
case '':
// If added in 'other' location, we don't need to add here; if set to
// None, then no need to load.
break;
}
}
/**
* Implements hook_menu().
*/
function font_awesome_menu() {
$items['admin/config/user-interface/font-awesome'] = array(
'title' => 'Font Awesome',
'description' => 'Include Font Awesome icons via CSS classes in your website.',
'page callback' => 'backdrop_get_form',
'page arguments' => array('font_awesome_admin_form'),
'access arguments' => array('administer site configuration'),
'file' => 'font_awesome.admin.inc',
);
return $items;
}
/**
* Implements hook_icon_info().
*/
function font_awesome_icon_info() {
return _font_awesome_load_icons();
}
/**
* Loads the icons from the Font Awesome icons into a keyed array.
*/
function _font_awesome_load_icons() {
$icons = cache_get('font_awesome_icons_array');
if (!empty($icons)) {
return $icons->data;
}
$icons = array();
$subpaths = array('brands', 'regular', 'solid');
foreach ($subpaths as $subpath) {
$icon_directory = backdrop_get_path('module', 'font_awesome') . '/icons/' . $subpath;
$icon_list = scandir($icon_directory);
foreach ($icon_list as $icon) {
if (substr($icon, -4) == '.svg') {
$icon_name = substr($icon, 0, -4);
$icons['font-awesome-' . $icon_name] = array(
'name' => $icon_name,
'directory' => $icon_directory,
);
}
}
}
cache_set('font_awesome_icons_array', $icons, 'cache', CACHE_PERMANENT);
return $icons;
}