-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathPlugin.php
160 lines (147 loc) · 6.47 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php namespace Winter\Builder;
use Event;
use Lang;
use Backend;
use System\Classes\PluginBase;
use System\Classes\CombineAssets;
use Winter\Builder\Classes\StandardControlsRegistry;
use Winter\Builder\Classes\StandardBehaviorsRegistry;
use Illuminate\Support\Facades\Validator;
use Winter\Builder\Rules\Reserved;
class Plugin extends PluginBase
{
public function pluginDetails()
{
return [
'name' => 'winter.builder::lang.plugin.name',
'description' => 'winter.builder::lang.plugin.description',
'author' => 'Winter CMS',
'icon' => 'icon-wrench',
'homepage' => 'https://github.com/wintercms/wn-builder-plugin',
'replaces' => ['RainLab.Builder' => '<= 1.1.0'],
];
}
public function registerComponents()
{
return [
'Winter\Builder\Components\RecordList' => 'builderList',
'Winter\Builder\Components\RecordDetails' => 'builderDetails'
];
}
public function registerPermissions()
{
return [
'winter.builder.manage_plugins' => [
'tab' => 'winter.builder::lang.plugin.name',
'label' => 'winter.builder::lang.plugin.manage_plugins',
],
];
}
public function registerNavigation()
{
return [
'builder' => [
'label' => 'winter.builder::lang.plugin.name',
'url' => Backend::url('winter/builder'),
'icon' => 'icon-wrench',
'iconSvg' => 'plugins/winter/builder/assets/images/builder-icon.svg',
'permissions' => ['winter.builder.manage_plugins'],
'order' => 400,
'sideMenu' => [
'database' => [
'label' => 'winter.builder::lang.database.menu_label',
'icon' => 'icon-database',
'url' => 'javascript:;',
'attributes' => ['data-menu-item'=>'database'],
'permissions' => ['winter.builder.manage_plugins']
],
'models' => [
'label' => 'winter.builder::lang.model.menu_label',
'icon' => 'icon-file-code',
'url' => 'javascript:;',
'attributes' => ['data-menu-item'=>'models'],
'permissions' => ['winter.builder.manage_plugins']
],
'permissions' => [
'label' => 'winter.builder::lang.permission.menu_label',
'icon' => 'icon-unlock',
'url' => '#',
'attributes' => ['data-no-side-panel'=>'true', 'data-builder-command'=>'permission:cmdOpenPermissions', 'data-menu-item'=>'permissions'],
'permissions' => ['winter.builder.manage_plugins']
],
'menus' => [
'label' => 'winter.builder::lang.menu.menu_label',
'icon' => 'icon-sitemap',
'url' => 'javascript:;',
'attributes' => ['data-no-side-panel'=>'true', 'data-builder-command'=>'menus:cmdOpenMenus', 'data-menu-item'=>'menus'],
'permissions' => ['winter.builder.manage_plugins']
],
'controllers' => [
'label' => 'winter.builder::lang.controller.menu_label',
'icon' => 'icon-signs-post',
'url' => 'javascript:;',
'attributes' => ['data-menu-item'=>'controllers'],
'permissions' => ['winter.builder.manage_plugins']
],
'versions' => [
'label' => 'winter.builder::lang.version.menu_label',
'icon' => 'icon-code-fork',
'url' => 'javascript:;',
'attributes' => ['data-menu-item'=>'version'],
'permissions' => ['winter.builder.manage_plugins']
],
'localization' => [
'label' => 'winter.builder::lang.localization.menu_label',
'icon' => 'icon-globe',
'url' => 'javascript:;',
'attributes' => ['data-menu-item'=>'localization'],
'permissions' => ['winter.builder.manage_plugins']
]
]
]
];
}
public function registerSettings()
{
return [
'config' => [
'label' => 'winter.builder::lang.plugin.name',
'icon' => 'icon-wrench',
'description' => 'winter.builder::lang.settings.menu_desc',
'class' => 'Winter\Builder\Models\Settings',
'permissions' => ['winter.builder.manage_plugins'],
'order' => 600
]
];
}
public function boot()
{
Event::listen('pages.builder.registerControls', function ($controlLibrary) {
new StandardControlsRegistry($controlLibrary);
});
Event::listen('pages.builder.registerControllerBehaviors', function ($behaviorLibrary) {
new StandardBehaviorsRegistry($behaviorLibrary);
});
// Register reserved keyword validation
Event::listen('translator.beforeResolve', function ($key, $replaces, $locale) {
if ($key === 'validation.reserved') {
return Lang::get('winter.builder::lang.validation.reserved');
}
});
Validator::extend('reserved', Reserved::class);
Validator::replacer('reserved', function ($message, $attribute, $rule, $parameters) {
// Fixes lowercase attribute names in the new plugin modal form
return ucfirst($message);
});
}
public function register()
{
/*
* Register asset bundles
*/
CombineAssets::registerCallback(function ($combiner) {
$combiner->registerBundle('$/winter/builder/assets/less/builder.less');
$combiner->registerBundle('$/winter/builder/assets/js/build.js');
});
}
}