Skip to content

Commit

Permalink
Issue #35: Add support for FontAwesome 5.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jen Lampton committed Aug 28, 2021
1 parent 9a60285 commit 06f96fa
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
10 changes: 4 additions & 6 deletions on_the_web.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ function on_the_web_settings_form($form, &$form_state) {
'icons_url' => 'http://forkaweso.me/Fork-Awesome/icons',
'description' => t('The FontAwesome Fork'),
),
/* @todo Support FA5?
'fontawesome_5' => array(
'key' => '5.x.x',
'label' => 'FontAwesome 5.x',
'icons_url' => 'https://fontawesome.com/v5.15/icons',
'description' => t('The latest version of FontAwesome. <a href=":faurl">FontAwesome account</a> Required.', array(':faurl' => 'https://fontawesome.com/start')),
),
*/
);

$form['version'] = array(
Expand All @@ -75,10 +73,9 @@ function on_the_web_settings_form($form, &$form_state) {

$form['version']['#options'] = $source_options;

/* @todo Support FA5?
$form['kit_hash'] = array(
'#type' => 'textfield',
'#title' => t('FontAwesome Kit Hash'),
'#title' => t('FontAwesome 5.x Kit Hash'),
'#default_value' => $config->get('kit_hash'),
'#attributes' => array(
'placeholder' => 'abcdefghij',
Expand All @@ -87,11 +84,10 @@ function on_the_web_settings_form($form, &$form_state) {
'#states' => array(
'visible' => array(
':input[name="type"]' => array('value' => 'font'),
':input[name="version"]' => array('value' => '5.0.0'),
':input[name="version"]' => array('value' => '5.x.x'),
),
),
);
*/

$form['size'] = array(
'#type' => 'radios',
Expand Down Expand Up @@ -160,6 +156,8 @@ function on_the_web_settings_form_submit($form, &$form_state) {
$config = config('on_the_web.settings');
$config->set('type', $form_state['values']['type']);
$config->set('square', $form_state['values']['square']);
$config->set('version', $form_state['values']['version']);
$config->set('kit_hash', $form_state['values']['kit_hash']);
$config->set('size', $form_state['values']['size']);
$config->set('sitename', $form_state['values']['sitename']);
$config->set('target', $form_state['values']['target']);
Expand Down
55 changes: 33 additions & 22 deletions on_the_web.module
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,13 @@ function on_the_web_display_block($delta, $settings = array(), $contexts = array
if (isset($info['fa-icon'])) {
$icon = $info['fa-icon'];
}
// Only use a square version if it exists.
// Only use a square icon if it exists.
if ($config->get('square') == TRUE && isset($info['fa-icon-square'])) {
$icon = $info['fa-icon-square'];

if ($config->get('version') == '5.x.x' && $service == 'linkedin') {
$icon = $info['fa-icon'];
}
}
}

Expand All @@ -215,29 +219,36 @@ function on_the_web_display_block($delta, $settings = array(), $contexts = array
'#weight' => $config->get($service . '_weight'),
);
}
}

if ($type == 'anchor') {
$links['#attached']['css'][] = backdrop_get_path('module', 'on_the_web') . '/css/on_the_web.css';
}
elseif ($type == 'font') {
if (!module_exists('font_awesome')) {

$version = $config->get('version');
switch ($version) {
case '4.7.0':
$font_url = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css';
break;
case '1.2.0':
$font_url = 'https://cdn.jsdelivr.net/npm/[email protected]/css/fork-awesome.min.css';
break;
/* @todo Support FA5
case '5.x.x':
$hash = $config->get('kit_hash');
$font_url = 'https://kit.fontawesome.com/' . $hash . '.js';
break;
*/
}
// Add the assets.
if ($type == 'anchor') {
$links['#attached']['css'][] = backdrop_get_path('module', 'on_the_web') . '/css/on_the_web.css';
}
elseif ($type == 'font') {
if (!module_exists('font_awesome')) {

$version = $config->get('version');
switch ($version) {
case '4.7.0':
$font_url = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css';
break;
case '1.2.0':
$font_url = 'https://cdn.jsdelivr.net/npm/[email protected]/css/fork-awesome.min.css';
break;
case '5.x.x':
//$font_url = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/brands.min.css';
// Add V4 shims?
//$links['#attached']['css']['https://use.fontawesome.com/releases/v5.15.4/css/v4-shims.css'] = array('type' => 'external');
$hash = $config->get('kit_hash');
if (!empty($hash)) {
$font_js_url = 'https://kit.fontawesome.com/' . $hash . '.js';
$links['#attached']['js'][$font_js_url] = array('type' => 'external');
}
break;
}

if (isset($font_url)) {
$links['#attached']['css'][$font_url] = array('type' => 'external');
}
}
Expand Down
5 changes: 4 additions & 1 deletion on_the_web.theme.inc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ function theme_on_the_web_item($variables) {

// Add the font awesome icon classes with support for v5.
$icon_classes = array($icon, 'fa-fw');
if (module_exists('font_awesome') && config_get('font_awesome.settings', 'fontawesome') == 'v5') {

if ((!module_exists('font_awesome') && $config->get('version') == '5.x.x')
|| (module_exists('font_awesome') && config_get('font_awesome.settings', 'fontawesome') == 'v5')) {

if ($service == 'rss') {
$icon_classes[] = 'fas';
}
Expand Down

0 comments on commit 06f96fa

Please sign in to comment.