Exception - No font settings
Closed this issue · 2 comments
gfringeli commented
If I do not define any font settings the package is running into an exception. The bug is caused in FontImplementation::evaluate().
Additionally, an exception is thrown if 'variants' has not been set for a font's value. Before trying to access $fontSetting['value']['variants']
, its existence should be checked with array_key_exists()
.
public function evaluate() {
$settings = $this->buildService->buildThemeSettings();
$fontSettings = $settings['font']['type']['font']; // will be null (if no font settings have been configured)
$fonts = $this->buildService->buildFontOptions();
$externalFonts = [];
// an exception is thrown; php does not allow to loop over a null variable
foreach ($fontSettings as $fontSetting) {
/** @var Font $font */
$font = $this->compileService->findFontByName($fontSetting['value']['family'], $fonts);
// Check if at least one font variant is available
//$variantsArray = json_decode($fontSetting['value']['variants']);
// possible solution
$value = $fontSetting['value'];
if (array_key_exists('variants',$value)) {
$variantsArray = json_decode($value['variants']);
}
if (isset($variantsArray) && is_array($variantsArray) && count($variantsArray) > 0 && isset($font)) {
switch ($font) {
case ($font->getFontSource() === Font::FONT_SOURCE_GOOGLE):
$externalFonts['google'][$fontSetting['value']['family']]['settings'] = $fontSetting;
break;
case ($font->getFontSource() === Font::FONT_SOURCE_CDN):
$externalFonts['cdn'][$fontSetting['value']['family']]['font'] = $font;
$externalFonts['cdn'][$fontSetting['value']['family']]['settings'] = $fontSetting;
break;
default:
}
}
}
$html = $this->getFontLinkTag($externalFonts);
return $html;
}
akappler commented
Would you mind to fix it and send a PR?
kdambekalns commented
Fixed since 3.1.3