5 * Websafe Fonts Test module file.
9 * Implements hook_fontyourface_api().
11 function websafe_fonts_test_fontyourface_api() {
14 'name' => 'Websafe Fonts',
19 * Implements hook_page_attachments().
21 function websafe_fonts_test_page_attachments(&$page) {
22 $enabled_fonts = &drupal_static('fontyourface_fonts', []);
23 foreach ($enabled_fonts as $font) {
24 if ($font->pid->value == 'websafe_fonts_test') {
25 $page['#attached']['html_head'][] = [
27 '#type' => 'html_tag',
30 'name' => 'Websafe Font',
31 'content' => $font->label(),
33 ], 'fontyourface-websafe-fonts-test-' . $font->id(),
40 * Implements hook_fontyourface_import().
42 function websafe_fonts_test_fontyourface_import($font_context = []) {
43 $context = $font_context;
44 if (empty($context['sandbox'])) {
45 $context['sandbox']['fonts'] = _websafe_fonts_test_get_fonts_from_api();
46 $context['sandbox']['progress'] = 0;
47 $context['sandbox']['max'] = count($context['sandbox']['fonts']);
49 $font = array_shift($context['sandbox']['fonts']);
51 fontyourface_save_font($font);
52 $context['message'] = "Imported {$context['sandbox']['progress']} of {$context['sandbox']['max']}";
53 $context['sandbox']['progress']++;
54 $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
57 drupal_set_message(t('Imported @count fonts from Websafe Fonts', ['@count' => $context['sandbox']['progress']]));
63 * Retrieves all Websafe fonts.
65 function _websafe_fonts_test_get_fonts_from_api() {
69 'url' => 'https://en.wikipedia.org/wiki/Arial',
70 'provider' => 'websafe_fonts_test',
71 'css_family' => 'Arial',
72 'css_style' => 'normal',
73 'css_weight' => '400',
76 'foundry' => 'Monotype Imaging',
78 'license' => 'Proprietary',
95 'url' => 'https://en.wikipedia.org/wiki/Verdana',
96 'provider' => 'websafe_fonts_test',
97 'css_family' => 'Verdana',
98 'css_style' => 'normal',
99 'css_weight' => '400',
100 'designer' => 'Matthew Carter',
101 'designer_url' => 'https://en.wikipedia.org/wiki/Matthew_Carter',
102 'foundry' => 'Microsoft',
103 'foundry_url' => 'https://www.microsoft.com',
106 'classification' => [
116 'name' => 'Courier New',
117 'url' => 'https://en.wikipedia.org/wiki/Courier_(typeface)',
118 'provider' => 'websafe_fonts_test',
119 'css_family' => 'Courier New',
120 'css_style' => 'normal',
121 'css_weight' => '400',
123 'designer_url' => '',
128 'classification' => [
139 'url' => 'https://en.wikipedia.org/wiki/Georgia_(typeface)',
140 'provider' => 'websafe_fonts_test',
141 'css_family' => 'Georgia',
142 'css_style' => 'normal',
143 'css_weight' => '400',
144 'designer' => 'Matthew Carter',
145 'designer_url' => 'https://en.wikipedia.org/wiki/Matthew_Carter',
146 'foundry' => 'Microsoft',
147 'foundry_url' => 'https://www.microsoft.com',
150 'classification' => [