Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / fontyourface / fontyourface.install
1 <?php
2
3 /**
4  * @file
5  * Font-Your-Face install/update/uninstall hook implementation.
6  */
7
8 use Drupal\Core\Field\FieldStorageDefinitionInterface;
9 use Drupal\field\Entity\FieldConfig;
10 use Drupal\field\Entity\FieldStorageConfig;
11 use Drupal\taxonomy\Entity\Vocabulary;
12 use Drupal\fontyourface\Entity\Font;
13
14 /**
15  * Implements hook_install().
16  */
17 function fontyourface_install() {
18   module_set_weight('fontyourface', 1);
19   drupal_set_message(t('If you have not yet enabled any @font-your-face provider modules, please do so. If you have already enabled @font-your-face provider modules, please use the font settings page in the appearance section to import fonts from them.'));
20 }
21
22 /**
23  * Implements hook_uninstall().
24  */
25 function fontyourface_uninstall() {
26   $vids = [
27     'font_classification',
28     'font_tags',
29     'languages_supported',
30     'font_designer',
31     'font_foundry',
32   ];
33   foreach ($vids as $vid) {
34     $vocabulary = Vocabulary::load($vid);
35     if (!empty($vocabulary)) {
36       $vocabulary->delete();
37     }
38   }
39 }
40
41 /**
42  * Updates fonts which are enabled to have enabled property in Font status.
43  */
44 function fontyourface_update_8001() {
45   $fonts = Font::loadEnabledFonts();
46   foreach ($fonts as $font) {
47     $font->enable();
48   }
49 }
50
51 /**
52  * Adds classification, languages, tags vocabularies and fields from config.
53  */
54 function fontyourface_update_8002() {
55   $classification = Vocabulary::create([
56     'name' => 'Classification',
57     'description' => 'This is the general font type.',
58     'vid' => 'font_classification',
59   ]);
60   $classification->save();
61
62   $languages_supported = Vocabulary::create([
63     'name' => 'Languages Supported',
64     'description' => 'The languages supported by the font.',
65     'vid' => 'languages_supported',
66   ]);
67   $languages_supported->save();
68
69   $tags = Vocabulary::create([
70     'name' => 'Font Tags',
71     'description' => 'The tags that came with the font.',
72     'vid' => 'font_tags',
73   ]);
74   $tags->save();
75
76   $foundry = Vocabulary::create([
77     'name' => 'Font Foundry',
78     'description' => 'Font Foundry',
79     'vid' => 'font_foundry',
80   ]);
81   $foundry->save();
82
83   $designer = Vocabulary::create([
84     'name' => 'Font Designer',
85     'description' => 'Font Designer',
86     'vid' => 'font_designer',
87   ]);
88   $designer->save();
89
90   // field_classification.
91   $classification_field_storage = FieldStorageConfig::create([
92     'field_name' => 'field_classification',
93     'entity_type' => 'font',
94     'translatable' => TRUE,
95     'entity_types' => [],
96     'settings' => [
97       'target_type' => 'taxonomy_term',
98     ],
99     'type' => 'entity_reference',
100     'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
101   ]);
102   $classification_field_storage->save();
103
104   $classification_field = FieldConfig::create([
105     'label' => 'Classification',
106     'field_name' => 'field_classification',
107     'field_storage' => $classification_field_storage,
108     'entity_type' => 'font',
109     'bundle' => 'font',
110     'settings' => [
111       'handler' => 'default:taxonomy_term',
112       'handler_settings' => [
113         // Reference a single vocabulary.
114         'target_bundles' => [
115           'font_classification' => 'font_classification',
116         ],
117         // Enable auto-create.
118         'auto_create' => TRUE,
119         'auto_create_bundle' => FALSE,
120         'sort' => [
121           'field' => '_none',
122         ],
123       ],
124     ],
125     'translatable' => FALSE,
126   ]);
127   $classification_field->save();
128
129   // field_supported_languages.
130   $supported_languages_field_storage = FieldStorageConfig::create([
131     'field_name' => 'field_supported_languages',
132     'entity_type' => 'font',
133     'translatable' => TRUE,
134     'entity_types' => [],
135     'settings' => [
136       'target_type' => 'taxonomy_term',
137     ],
138     'type' => 'entity_reference',
139     'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
140   ]);
141   $supported_languages_field_storage->save();
142
143   $supported_languages_field = FieldConfig::create([
144     'label' => 'Supported Languages',
145     'field_name' => 'field_supported_languages',
146     'field_storage' => $supported_languages_field_storage,
147     'entity_type' => 'font',
148     'bundle' => 'font',
149     'settings' => [
150       'handler' => 'default:taxonomy_term',
151       'handler_settings' => [
152         // Reference a single vocabulary.
153         'target_bundles' => [
154           'languages_supported' => 'languages_supported',
155         ],
156         // Enable auto-create.
157         'auto_create' => TRUE,
158         'auto_create_bundle' => FALSE,
159         'sort' => [
160           'field' => '_none',
161         ],
162       ],
163     ],
164     'translatable' => FALSE,
165   ]);
166   $supported_languages_field->save();
167
168   // field_tags.
169   $tags_field_storage = FieldStorageConfig::create([
170     'field_name' => 'field_tags',
171     'entity_type' => 'font',
172     'translatable' => TRUE,
173     'entity_types' => [],
174     'settings' => [
175       'target_type' => 'taxonomy_term',
176     ],
177     'type' => 'entity_reference',
178     'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
179   ]);
180   $tags_field_storage->save();
181
182   $tags_field = FieldConfig::create([
183     'label' => 'Tags',
184     'field_name' => 'field_tags',
185     'field_storage' => $tags_field_storage,
186     'entity_type' => 'font',
187     'bundle' => 'font',
188     'settings' => [
189       'handler' => 'default:taxonomy_term',
190       'handler_settings' => [
191         // Reference a single vocabulary.
192         'target_bundles' => [
193           'font_designer' => 'font_designer',
194           'font_foundry' => 'font_foundry',
195           'font_tags' => 'font_tags',
196         ],
197         // Enable auto-create.
198         'auto_create' => TRUE,
199         'auto_create_bundle' => FALSE,
200         'sort' => [
201           'field' => '_none',
202         ],
203       ],
204     ],
205     'translatable' => FALSE,
206   ]);
207   $tags_field->save();
208 }
209
210 /**
211  * Updates fontyourface and submodule weights since there are issues around ordering.
212  */
213 function fontyourface_update_8003() {
214   // Set the module weight. There is some general Drupal funk around module weights during install.
215   module_set_weight('fontyourface', 1);
216   foreach (\Drupal::moduleHandler()->getImplementations('fontyourface_api') as $module_name) {
217     module_set_weight($module_name, 10);
218   }
219 }
220
221 /**
222  * Updates fontyourface font displays to be stored in files.
223  */
224 function fontyourface_update_8004() {
225   $pager = 0;
226   while (TRUE) {
227     $storage_handler = \Drupal::entityManager()->getStorage('font_display');
228     $fdids = \Drupal::entityQuery('font_display')
229       ->range($pager, 50)
230       ->execute();
231     if (!empty($fdids)) {
232       $styles = $storage_handler->loadMultiple(array_keys($fdids));
233       foreach ($styles as $style) {
234         fontyourface_save_and_generate_font_display_css($style);
235       }
236     }
237     else {
238       break;
239     }
240     $pager++;
241   }
242 }
243
244 /**
245  * Ensure to flush all caches.
246  */
247 function fontyourface_update_8005() {
248   drupal_flush_all_caches();
249 }