-
Notifications
You must be signed in to change notification settings - Fork 8
/
hooks.php
42 lines (35 loc) · 1.38 KB
/
hooks.php
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
<?php
function mergeTranslations($array1, $array2)
{
foreach ($array2 as $key => $value) {
if (isset($array1[$key]) && is_array($value)) {
$array1[$key] = mergeTranslations($array1[$key], $value);
} else {
$array1[$key] = $value;
}
}
return $array1;
}
// This method adds plugin options as translations for the current panel language, allowing these
// options to be accessed in the VUE part of the plugin using the $t()-helper.
// This is a workaround and might cause issues ¯\_(ツ)_/¯
function enhanceTranslationsWithInternalOptions($translations)
{
$targetKey = "gearsdigital.enhanced-toolbar-link-dialog.target-field";
$anchorKey = "gearsdigital.enhanced-toolbar-link-dialog.anchor-field";
$language = kirby()->panelLanguage();
$enhanced[$language] = [
$targetKey => option($targetKey),
$anchorKey => option($anchorKey),
];
return mergeTranslations($translations, $enhanced);
}
return [
'system.loadPlugins:after' => function () {
$translations = option('gearsdigital.enhanced-toolbar-link-dialog.translations', []);
$translations = enhanceTranslationsWithInternalOptions($translations);
if (count($translations) > 0) {
kirby()->extend(['translations' => $translations], kirby()->plugin('gearsdigital/enhanced-toolbar-link-dialog'));
}
},
];