diff --git a/CHANGELOG.md b/CHANGELOG.md
index bf7d75f..4c047d1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
# Changelog
## WIP
+- Add support for Google fonts
- Move to Web Asset Manager for assets
## 1.1.2
diff --git a/component.php b/component.php
index 87ba6b7..e27881b 100644
--- a/component.php
+++ b/component.php
@@ -8,9 +8,6 @@
defined('_JEXEC') or die;
-use Joomla\CMS\HTML\HTMLHelper;
-use Joomla\CMS\Factory;
-
/** @var Joomla\CMS\Document\HtmlDocument $this */
$wa = $this->getWebAssetManager();
diff --git a/fields/fonts.php b/fields/fonts.php
new file mode 100644
index 0000000..bafb30d
--- /dev/null
+++ b/fields/fonts.php
@@ -0,0 +1,115 @@
+getLayoutData();
+
+ $data['options'] = (array) $this->getOptions();
+
+ return $this->getRenderer($this->layout)->render($data);
+ }
+
+ /**
+ * Method to get the field options.
+ *
+ * @return array The field option objects.
+ */
+ protected function getOptions()
+ {
+ $options = new Registry;
+ $options->set('userAgent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0');
+ $http = HttpFactory::getHttp($options);
+
+ $array = [[
+ 'value' => '',
+ 'text' => 'None',
+ ]];
+
+ try
+ {
+ $result = $http->get($this->apiUrl . $this->getParams()->get('google-fonts-api-key', ''));
+ $json = json_decode($result->body);
+ }
+ catch (RuntimeException $e)
+ {
+ Factory::getApplication()->enqueueMessage('Unable to fetch API data', 'error');
+ throw new \RuntimeException('Unable to fetch API data.', $e->getCode(), $e);
+ }
+
+ if (isset($json->error))
+ {
+ return Factory::getApplication()->enqueueMessage($json->error->message, 'error');
+ }
+
+ foreach ($json->items as $font)
+ {
+ $tmp = [
+ 'value' => $font->family,
+ 'text' => $font->family,
+ ];
+ $array[] = (object) $tmp;
+ }
+
+ return $array;
+ }
+
+ /**
+ * Method to get the lightning template parameters.
+ *
+ * @return Registry The params object.
+ */
+ protected function getParams()
+ {
+ $db = Factory::getDbo();
+
+ $db->setQuery(
+ $db->getQuery(true)
+ ->select('params')
+ ->from('#__template_styles')
+ ->where('template = ' . $db->q('lightning'))
+ ->where('client_id = 0')
+ );
+ $registry = new Registry;
+ $registry->loadString($db->loadResult());
+
+ return $registry;
+ }
+}
diff --git a/index.php b/index.php
index 78c7550..a7415e7 100644
--- a/index.php
+++ b/index.php
@@ -20,6 +20,7 @@
$pageclass = $app->getMenu()->getActive()->getParams()->get('pageclass_sfx');
$themeSwitcher = (boolean)$this->params->get('theme-switcher', 1);
$fontAwesome = (boolean)$this->params->get('font-awesome-thats-actually-rather-shit', 1);
+$googleFont = $this->params->get('google-font', '');
// Load switcher CSS
if ($themeSwitcher)
@@ -36,6 +37,19 @@
$wa->useStyle('fontawesome.css');
}
+// Google font
+if ($googleFont !== '')
+{
+ $fontFamily = str_replace(' ', '+', $googleFont);
+ $this->getPreloadManager()->preconnect('https://fonts.googleapis.com', []);
+ $this->getPreloadManager()->preconnect('https://fonts.gstatic.com', []);
+ $this->addHeadLink('https://fonts.googleapis.com/css2?family=' . $fontFamily . '&display=swap', 'stylesheet', 'rel');
+
+ $wa->addInlineStyle(':root {
+ --hiq-font-family-base: "' . $googleFont . '";
+ }');
+}
+
// Load switcher JS
// This should be loaded even if the themeSwitcher is disabled, so that the system preference will still dictate the theme
$wa->useScript('switch.js');
diff --git a/language/en-GB/en-GB.tpl_lightning.ini b/language/en-GB/en-GB.tpl_lightning.ini
index 9995035..cd21a60 100644
--- a/language/en-GB/en-GB.tpl_lightning.ini
+++ b/language/en-GB/en-GB.tpl_lightning.ini
@@ -14,6 +14,12 @@ TPL_LIGHTNING_FIELDSET_CSS_OVERRIDES="CSS Overrides"
TPL_LIGHTNING_FIELDSET_LOGO="Logo"
TPL_LIGHTNING_FIELDSET_OPTIMIZE="Optimize"
+TPL_LIGHTNING_GOOGLE_FONTS="Google Fonts"
+TPL_LIGHTNING_GOOGLE_FONTS_API_KEY="Google Fonts API Key"
+TPL_LIGHTNING_GOOGLE_FONTS_API_KEY_DESC="Entering Google Fonts API key will be used to populate the fonts list below"
+
+TPL_LIGHTNING_LOAD_FONT_AWESOME="Load Font Awesome"
+
TPL_LIGHTNING_LOGO_LABEL="Site logo file"
TPL_LIGHTNING_LOGO_SVG_LABEL="Site logo SVG"
TPL_LIGHTNING_LOGO_SVG_DESC="Add the SVG code for your logo. This will take presidence over the Site logo file
option."
diff --git a/templateDetails.xml b/templateDetails.xml
index 4e69e54..a908409 100644
--- a/templateDetails.xml
+++ b/templateDetails.xml
@@ -78,11 +78,26 @@
type="radio"
layout="joomla.form.field.radio.switcher"
default="1"
- label="Load Font awesome"
+ label="TPL_LIGHTNING_LOAD_FONT_AWESOME"
>
+
+