-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPlugin.php
More file actions
100 lines (81 loc) · 3.2 KB
/
Copy pathPlugin.php
File metadata and controls
100 lines (81 loc) · 3.2 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
<?php
namespace JanVince\SmallGDPR;
use System\Classes\PluginBase;
use System\Classes\PluginManager;
use JanVince\SmallGDPR\Models\CookiesSettings;
use Config;
use Backend;
use Validator;
use Log;
use Yaml;
use File;
use Storage;
class Plugin extends PluginBase {
public function boot() {
// Compat: the translate globe popup (HasTranslatable) calls formBeforeSave()/
// formAfterSave() on the settings controller, which System\Controllers\Settings lacks.
// Add no-op stubs only when missing → the patch disables itself once core fixes this.
if (class_exists(\System\Controllers\Settings::class)) {
\System\Controllers\Settings::extend(function ($controller) {
if (!$controller->methodExists('formBeforeSave')) {
$controller->addDynamicMethod('formBeforeSave', function ($model) {});
}
if (!$controller->methodExists('formAfterSave')) {
$controller->addDynamicMethod('formAfterSave', function ($model) {});
}
});
}
}
public function registerSettings() {
return [
'cookies' => [
'label' => 'janvince.smallgdpr::lang.settings.cookies.name',
'description' => 'janvince.smallgdpr::lang.settings.cookies.description',
'category' => 'Small plugins',
'icon' => 'icon-desktop',
'class' => 'JanVince\SmallGDPR\Models\CookiesSettings',
'keywords' => 'gdpr cookies bar consent',
'order' => 990,
'size' => 'adaptive',
'permissions' => ['janvince.smallgdpr.access_cookies_settings'],
],
];
}
public function registerComponents() {
return [
'JanVince\SmallGDPR\Components\CookiesConfig' => 'cookiesConfig',
'JanVince\SmallGDPR\Components\CookiesBar' => 'cookiesBar',
'JanVince\SmallGDPR\Components\CookiesManage' => 'cookiesManage',
];
}
public function registerMarkupTags() {
$settings = CookiesSettings::instance();
$pluginManager = \System\Classes\PluginManager::instance()->findByIdentifier('Rainlab.Translate');
if ($pluginManager && !$pluginManager->disabled) {
$settings->translateContext(\RainLab\Translate\Classes\Translator::instance()->getLocale());
}
return [
'filters' => [],
'functions' => [
'cookiesSettingsGet' => function ($value, $default = NULL) use ($settings){
if(empty($settings->$value)) {
return $default;
} else {
return $settings->$value;
}
}
]
];
}
public function registerFormWidgets() {
return [
'JanVince\SmallGDPR\FormWidgets\ImportPreset' => 'importpreset',
'JanVince\SmallGDPR\FormWidgets\ExportPreset' => 'exportpreset',
];
}
public function registerPageSnippets() {
return [
'\JanVince\SmallGDPR\Components\CookiesManage' => 'cookiesManage'
];
}
}