-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboot.php
More file actions
71 lines (60 loc) · 2.58 KB
/
boot.php
File metadata and controls
71 lines (60 loc) · 2.58 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
<?php
/** @var rex_addon $this */
// Autoloader für Namespace
rex_autoload::addDirectory(rex_path::addon('yform_lang_fields', 'lib'));
// YForm-Feldklassen laden (im globalen Namespace für YForm-Erkennung)
require_once rex_path::addon('yform_lang_fields', 'lib/rex_yform_value_lang_text.php');
require_once rex_path::addon('yform_lang_fields', 'lib/rex_yform_value_lang_textarea.php');
require_once rex_path::addon('yform_lang_fields', 'lib/rex_yform_value_lang_media.php');
// Extension Points registrieren
rex_extension::register('PACKAGES_INCLUDED', function() {
// Templates registrieren
rex_yform::addTemplatePath(rex_path::addon('yform_lang_fields', 'ytemplates'));
});
// Assets für Backend einbinden
if (rex::isBackend()) {
rex_view::addCssFile($this->getAssetsUrl('lang-fields.css'));
rex_view::addJsFile($this->getAssetsUrl('lang-fields.js'));
// Sprachswitch-Dropdown in YForm-Listenansicht einfügen,
// wenn die Tabelle mindestens ein lang_*-Feld besitzt.
rex_extension::register('YFORM_DATA_LIST_LINKS', static function (rex_extension_point $ep): void {
$table = $ep->getParam('table');
if (!$table instanceof rex_yform_manager_table) {
return;
}
$fields = $table->getFields();
if (!\KLXM\YformLangFields\LangHelper::tableHasLangFields($fields)) {
return;
}
// Alle aktiven Sprachen als JSON für JS bereitstellen
$clangs = [];
foreach (rex_clang::getAll() as $clang) {
if ($clang->isOnline()) {
$clangs[] = [
'id' => $clang->getId(),
'code' => $clang->getCode(),
'name' => $clang->getName(),
];
}
}
if (count($clangs) < 2) {
return; // Nur eine Sprache → kein Dropdown nötig
}
$clangJson = json_encode($clangs, JSON_THROW_ON_ERROR);
// Button als dataset_link einhängen (HTML-String)
$subject = $ep->getSubject();
$datasetLinks = $subject['dataset_links'];
$datasetLinks[] = [
'label' => '<i class="rex-icon fa-language"></i>',
'url' => '#',
'attributes' => [
'class' => ['btn-default', 'ylf-clang-switch-trigger'],
'data-ylf-clangs' => $clangJson,
'title' => 'Sprache in Listenansicht',
'id' => 'ylf-clang-switch-trigger',
],
];
$subject['dataset_links'] = $datasetLinks;
$ep->setSubject($subject);
});
}