-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlugin.php
67 lines (58 loc) · 1.75 KB
/
Plugin.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
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
<?php namespace Vdomah\TranslateTabs;
use Cms\Models\ThemeData;
use System\Classes\PluginBase;
use Cms\Classes\Theme;
class Plugin extends PluginBase
{
public $require = ['RainLab.Translate'];
public function registerComponents()
{
}
public function registerSettings()
{
}
public function registerFormWidgets()
{
return [
'Vdomah\TranslateTabs\FormWidgets\Translations' => [
'label' => 'Translations',
'code' => 'translations'
],
];
}
public function boot()
{
ThemeData::extend(function($model) {
$theme = Theme::getActiveTheme();
$form = $theme->getConfigValue('form');
if (is_array($form)) {
$translations = $this->findThemeTrans($form);
if (is_array($translations)) {
$model->implement[] = 'RainLab.Translate.Behaviors.TranslatableModel';
$model->implement[] = 'Vdomah.TranslateTabs.Behaviors.TranslateTabbable';
$model->addDynamicProperty('translatable', array_keys($translations));
}
}
});
}
public function findThemeTrans($arr)
{
if (is_array($arr)) {
if (!count($arr))
return false;
} else {
return false;
}
if ($translations = array_get($arr, '_translations')) {
return array_get($translations, 'form.fields');
} else {
if (is_array($arr))
foreach ($arr as $item) {
if ($_trans = $this->findThemeTrans($item))
return $_trans;
}
else
return false;
}
}
}