Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #35: Add support for FontAwesome 5. #36

Merged
merged 1 commit into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 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',
'label' => 'FontAwesome 5.x (requires registration)',
'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,23 +73,24 @@ 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'),
'#field_prefix' => 'https://kit.fontawesome.com/',
'#field_suffix' => '.js',
'#size' => 20,
'#default_value' => $config->get('kit_hash'),
'#attributes' => array(
'placeholder' => 'abcdefghij',
),
'#description' => t('In order to use FontAwesome 5 you must <a href=":faurl">register your email address</a> to recieve a kit.'),
'#description' => t('A 10-digit hash from the FontAwesome Kit code. <a href=":faurl">Register with FontAwesome</a> to generate a Kit.'),
'#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 +159,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