-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhelfi_kasko_content.install
More file actions
136 lines (125 loc) · 3.65 KB
/
helfi_kasko_content.install
File metadata and controls
136 lines (125 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* @file
* Contains installation functions for Kasko instance.
*/
declare(strict_types=1);
use Drupal\Core\Entity\EntityStorageException;
use Drupal\helfi_kasko_content\SchoolUtility;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\user\Entity\Role;
/**
* Implements hook_install().
*/
function helfi_kasko_content_install() : void {
if (!Role::load('school_editor')) {
Role::create(['id' => 'school_editor', 'label' => 'Upper secondary school editor'])->save();
}
}
/**
* Set initial vocational study terms.
*/
function helfi_kasko_content_update_9002() {
$vocabulary = 'vocational_studies';
if (!Vocabulary::load($vocabulary)) {
return;
}
$vocationalStudies = [
0 => [
'en' => "Arts and humanities",
'fi' => "Humanistiset ja taidealat",
'sv' => "De humanistiska och konstnärliga områdena",
],
1 => [
'en' => "Business and administration",
'fi' => "Kauppa ja hallinto",
'sv' => "Handel och administration",
],
2 => [
'en' => "Natural sciences",
'fi' => "Luonnontieteet",
'sv' => "Natur och miljö",
],
3 => [
'en' => "Information and Communication Technologies",
'fi' => "Tietojenkäsittely ja tietoliikenne",
'sv' => "Informations- och kommunikationsteknik",
],
4 => [
'en' => "Engineering, manufacturing and construction",
'fi' => "Tekniikan alat",
'sv' => "Teknik branschen",
],
5 => [
'en' => "Health and welfare",
'fi' => "Terveys- ja hyvinvointialat",
'sv' => "Hälsovård och välfärd",
],
6 => [
'en' => "Services",
'fi' => "Palvelualat",
'sv' => "Servicebranschen",
],
];
// Add initial vocational study fields in English.
$langcode = 'en';
foreach ($vocationalStudies as $studyField) {
$term = Term::create([
'parent' => [],
'name' => $studyField[$langcode],
'vid' => $vocabulary,
'langcode' => $langcode,
]);
try {
$term->save();
}
catch (EntityStorageException $e) {
Drupal::logger('helfi_kasko_content')->error('Failed to add term @name. Message: @message',
[
'@name' => $studyField[$langcode],
'@message' => $e->getMessage(),
]);
}
// Add translations for all available languages.
foreach (['fi', 'sv'] as $translationLangcode) {
try {
$term->addTranslation($translationLangcode, [
'name' => $studyField[$translationLangcode],
])->save();
}
catch (\InvalidArgumentException $e) {
Drupal::logger('helfi_helsinki_neighbourhoods')->error('Failed to translate term @name. Message: @message',
[
'@name' => $studyField[$langcode],
'@message' => $e->getMessage(),
]);
}
}
}
}
/**
* Update schoolyear Drupal state.
*/
function helfi_kasko_content_update_9003() {
$highSchoolYear = \Drupal::state()->get('helfi_school_addons.school_year') ? (int) \Drupal::state()->get('helfi_school_addons.school_year') : 2023;
SchoolUtility::setCurrentHighSchoolYear(SchoolUtility::composeSchoolYear($highSchoolYear));
SchoolUtility::setCurrentComprehensiveSchoolYear('2023-2024');
}
/**
* Update school search translations.
*/
function helfi_kasko_content_update_9004() {
// Update translations manually as js translations might not
// get translated due to libraries not being loaded via render arrays.
foreach ([
'themes/contrib/hdbt/dist/js/school-search.min.js',
] as $file) {
_locale_parse_js_file($file);
}
}
/**
* UHF-10494 - Adds groups news paragraph to basic page.
*/
function helfi_kasko_content_update_9005() {
}