From 06f96fa93db8b6ada34007eb928ed58d3cfc8c88 Mon Sep 17 00:00:00 2001 From: Jen Lampton Date: Fri, 27 Aug 2021 18:51:39 -0700 Subject: [PATCH] Issue #35: Add support for FontAwesome 5. --- on_the_web.admin.inc | 10 ++++---- on_the_web.module | 55 ++++++++++++++++++++++++++------------------ on_the_web.theme.inc | 5 +++- 3 files changed, 41 insertions(+), 29 deletions(-) diff --git a/on_the_web.admin.inc b/on_the_web.admin.inc index 765efa3..a875401 100644 --- a/on_the_web.admin.inc +++ b/on_the_web.admin.inc @@ -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. FontAwesome account Required.', array(':faurl' => 'https://fontawesome.com/start')), ), - */ ); $form['version'] = array( @@ -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', @@ -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', @@ -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']); diff --git a/on_the_web.module b/on_the_web.module index f5e46fe..bb6829e 100755 --- a/on_the_web.module +++ b/on_the_web.module @@ -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']; + } } } @@ -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/fork-awesome@1.2.0/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/fork-awesome@1.2.0/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'); } } diff --git a/on_the_web.theme.inc b/on_the_web.theme.inc index 9810343..29401d0 100644 --- a/on_the_web.theme.inc +++ b/on_the_web.theme.inc @@ -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'; }