5 * Font-Your-Face install/update/uninstall hook implementation.
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;
15 * Implements hook_install().
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.'));
23 * Implements hook_uninstall().
25 function fontyourface_uninstall() {
27 'font_classification',
29 'languages_supported',
33 foreach ($vids as $vid) {
34 $vocabulary = Vocabulary::load($vid);
35 if (!empty($vocabulary)) {
36 $vocabulary->delete();
42 * Updates fonts which are enabled to have enabled property in Font status.
44 function fontyourface_update_8001() {
45 $fonts = Font::loadEnabledFonts();
46 foreach ($fonts as $font) {
52 * Adds classification, languages, tags vocabularies and fields from config.
54 function fontyourface_update_8002() {
55 $classification = Vocabulary::create([
56 'name' => 'Classification',
57 'description' => 'This is the general font type.',
58 'vid' => 'font_classification',
60 $classification->save();
62 $languages_supported = Vocabulary::create([
63 'name' => 'Languages Supported',
64 'description' => 'The languages supported by the font.',
65 'vid' => 'languages_supported',
67 $languages_supported->save();
69 $tags = Vocabulary::create([
70 'name' => 'Font Tags',
71 'description' => 'The tags that came with the font.',
76 $foundry = Vocabulary::create([
77 'name' => 'Font Foundry',
78 'description' => 'Font Foundry',
79 'vid' => 'font_foundry',
83 $designer = Vocabulary::create([
84 'name' => 'Font Designer',
85 'description' => 'Font Designer',
86 'vid' => 'font_designer',
90 // field_classification.
91 $classification_field_storage = FieldStorageConfig::create([
92 'field_name' => 'field_classification',
93 'entity_type' => 'font',
94 'translatable' => TRUE,
97 'target_type' => 'taxonomy_term',
99 'type' => 'entity_reference',
100 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
102 $classification_field_storage->save();
104 $classification_field = FieldConfig::create([
105 'label' => 'Classification',
106 'field_name' => 'field_classification',
107 'field_storage' => $classification_field_storage,
108 'entity_type' => 'font',
111 'handler' => 'default:taxonomy_term',
112 'handler_settings' => [
113 // Reference a single vocabulary.
114 'target_bundles' => [
115 'font_classification' => 'font_classification',
117 // Enable auto-create.
118 'auto_create' => TRUE,
119 'auto_create_bundle' => FALSE,
125 'translatable' => FALSE,
127 $classification_field->save();
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' => [],
136 'target_type' => 'taxonomy_term',
138 'type' => 'entity_reference',
139 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
141 $supported_languages_field_storage->save();
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',
150 'handler' => 'default:taxonomy_term',
151 'handler_settings' => [
152 // Reference a single vocabulary.
153 'target_bundles' => [
154 'languages_supported' => 'languages_supported',
156 // Enable auto-create.
157 'auto_create' => TRUE,
158 'auto_create_bundle' => FALSE,
164 'translatable' => FALSE,
166 $supported_languages_field->save();
169 $tags_field_storage = FieldStorageConfig::create([
170 'field_name' => 'field_tags',
171 'entity_type' => 'font',
172 'translatable' => TRUE,
173 'entity_types' => [],
175 'target_type' => 'taxonomy_term',
177 'type' => 'entity_reference',
178 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
180 $tags_field_storage->save();
182 $tags_field = FieldConfig::create([
184 'field_name' => 'field_tags',
185 'field_storage' => $tags_field_storage,
186 'entity_type' => 'font',
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',
197 // Enable auto-create.
198 'auto_create' => TRUE,
199 'auto_create_bundle' => FALSE,
205 'translatable' => FALSE,
211 * Updates fontyourface and submodule weights since there are issues around ordering.
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);
222 * Updates fontyourface font displays to be stored in files.
224 function fontyourface_update_8004() {
227 $storage_handler = \Drupal::entityManager()->getStorage('font_display');
228 $fdids = \Drupal::entityQuery('font_display')
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);
245 * Ensure to flush all caches.
247 function fontyourface_update_8005() {
248 drupal_flush_all_caches();