Version 1
[yaffs-website] / web / modules / contrib / fontyourface / tests / websafe_fonts_test / websafe_fonts_test.module
1 <?php
2
3 /**
4  * @file
5  * Websafe Fonts Test module file.
6  */
7
8 /**
9  * Implements hook_fontyourface_api().
10  */
11 function websafe_fonts_test_fontyourface_api() {
12   return [
13     'version' => '3',
14     'name' => 'Websafe Fonts',
15   ];
16 }
17
18 /**
19  * Implements hook_page_attachments().
20  */
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'][] = [
26         [
27           '#type' => 'html_tag',
28           '#tag' => 'meta',
29           '#attributes' => [
30             'name' => 'Websafe Font',
31             'content' => $font->label(),
32           ],
33         ], 'fontyourface-websafe-fonts-test-' . $font->id(),
34       ];
35     }
36   }
37 }
38
39 /**
40  * Implements hook_fontyourface_import().
41  */
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']);
48   }
49   $font = array_shift($context['sandbox']['fonts']);
50   if (!empty($font)) {
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'];
55   }
56   else {
57     drupal_set_message(t('Imported @count fonts from Websafe Fonts', ['@count' => $context['sandbox']['progress']]));
58   }
59   return $context;
60 }
61
62 /**
63  * Retrieves all Websafe fonts.
64  */
65 function _websafe_fonts_test_get_fonts_from_api() {
66   return [
67     (object) [
68       'name' => 'Arial',
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',
74       'designer' => '',
75       'designer_url' => '',
76       'foundry' => 'Monotype Imaging',
77       'foundry_url' => '',
78       'license' => 'Proprietary',
79       'license_url' => '',
80       'classification' => [
81         'sans-serif',
82         'Neo-grotesque',
83       ],
84       'language' => [
85         'en',
86       ],
87       'tags' => [
88         'Sans-serif',
89         'Robin Nocholas',
90         'Patricia Saunders',
91       ],
92     ],
93     (object) [
94       'name' => 'Verdana',
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',
104       'license' => '',
105       'license_url' => '',
106       'classification' => [
107         'Modern Humanist',
108         'sans-serif',
109       ],
110       'language' => [
111         'en',
112       ],
113       'tags' => [],
114     ],
115     (object) [
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',
122       'designer' => '',
123       'designer_url' => '',
124       'foundry' => '',
125       'foundry_url' => '',
126       'license' => '',
127       'license_url' => '',
128       'classification' => [
129         'monospace',
130         'slab-serif',
131       ],
132       'language' => [
133         'en',
134       ],
135       'tags' => [],
136     ],
137     (object) [
138       'name' => 'Georgia',
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',
148       'license' => '',
149       'license_url' => '',
150       'classification' => [
151         'serif',
152       ],
153       'language' => [
154         'en',
155       ],
156       'tags' => [
157         'Scotch Roman',
158         'Transitional',
159         'Didone',
160       ],
161     ],
162   ];
163 }