function fontyourface_page_attachments in @font-your-face 8.3
Implements hook_page_attachments().
File
- ./
fontyourface.module, line 97 - Contains fontyourface.module..
Code
function fontyourface_page_attachments(&$page) {
$config = \Drupal::config('fontyourface.settings');
$fonts =& drupal_static('fontyourface_fonts', []);
// Load all enabled fonts for theme if setting allows it.
if ($config
->get('load_all_enabled_fonts')) {
if (empty($config
->get('load_on_themes')) || in_array(\Drupal::theme()
->getActiveTheme()
->getName(), $config
->get('load_on_themes'))) {
foreach (Font::loadActivatedFonts() as $font) {
$fonts[$font->url->value] = $font;
}
}
}
$font_preview =& drupal_static('fontyourface_font_preview');
// On a font preview page, ONLY show the preview font and other base theme
// font.
if (empty($font_preview)) {
// We are dealing with a regular page.
$theme = \Drupal::theme()
->getActiveTheme()
->getName();
$styles = FontDisplay::loadByTheme($theme);
if (!empty($styles)) {
$page['#attached']['library'][] = 'fontyourface/font_display_' . $theme;
foreach ($styles as $style) {
$font = $style
->getFont();
if (!empty($font)) {
$fonts[$font->url->value] = $font;
}
}
}
}
}