This repository has been archived by the owner on Jul 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
241 lines (219 loc) · 7.45 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php namespace Gigafeed\Locations;
use Backend;
use OFFLINE\OpeningHours\Controllers\Locations;
use OFFLINE\OpeningHours\Models\Location;
use OFFLINE\OpeningHours\Models\Location as LocationModel;
use System\Classes\PluginBase;
/**
* Locations Plugin Information File
*/
class Plugin extends PluginBase
{
public $require = [
'Offline.OpeningHours'
];
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'Locations',
'description' => '',
'author' => 'Gigafeed',
'icon' => 'icon-map-pin'
];
}
/**
* Register method, called when the plugin is first registered.
*
* @return void
*/
public function register()
{
}
/**
* Boot method, called right before the request route.
*
* @return array
*/
public function boot()
{
Locations::extendFormFields(function ($form, $model, $context) {
if (!($model instanceof LocationModel)) {
return;
}
$form->addTabFields([
'physical_location[addr1]' => [
'label' => 'Address Line 1',
'tab' => 'Physical Location',
'span' => 'left',
'type' => 'text'
],
'physical_location[addr2]' => [
'label' => 'Address Line 2',
'tab' => 'Physical Location',
'span' => 'right',
'type' => 'text'
],
'physical_location[city]' => [
'label' => 'City',
'tab' => 'Physical Location',
'type' => 'text'
],
'physical_location[state]' => [
'label' => 'City',
'tab' => 'Physical Location',
'type' => 'dropdown',
'options' => [
'AL' => 'Alabama',
'AK' => 'Alaska',
'AZ' => 'Arizona',
'AR' => 'Arkansas',
'CA' => 'California',
'CO' => 'Colorado',
'CT' => 'Connecticut',
'DE' => 'Delaware',
'DC' => 'District Of Columbia',
'FL' => 'Florida',
'GA' => 'Georgia',
'HI' => 'Hawaii',
'ID' => 'Idaho',
'IL' => 'Illinois',
'IN' => 'Indiana',
'IA' => 'Iowa',
'KS' => 'Kansas',
'KY' => 'Kentucky',
'LA' => 'Louisiana',
'ME' => 'Maine',
'MD' => 'Maryland',
'MA' => 'Massachusetts',
'MI' => 'Michigan',
'MN' => 'Minnesota',
'MS' => 'Mississippi',
'MO' => 'Missouri',
'MT' => 'Montana',
'NE' => 'Nebraska',
'NV' => 'Nevada',
'NH' => 'New Hampshire',
'NJ' => 'New Jersey',
'NM' => 'New Mexico',
'NY' => 'New York',
'NC' => 'North Carolina',
'ND' => 'North Dakota',
'OH' => 'Ohio',
'OK' => 'Oklahoma',
'OR' => 'Oregon',
'PA' => 'Pennsylvania',
'RI' => 'Rhode Island',
'SC' => 'South Carolina',
'SD' => 'South Dakota',
'TN' => 'Tennessee',
'TX' => 'Texas',
'UT' => 'Utah',
'VT' => 'Vermont',
'VA' => 'Virginia',
'WA' => 'Washington',
'WV' => 'West Virginia',
'WI' => 'Wisconsin',
'WY' => 'Wyoming',
]
],
'physical_location[zipcode]' => [
'label' => 'City',
'tab' => 'Physical Location',
'type' => 'number'
],
]);
});
// Extend all backend form usage
\Event::listen('backend.form.extendFields', function ($widget) {
// Only for the User controller
if (!$widget->getController() instanceof Locations) {
return;
}
// Only for the User model
if (!$widget->model instanceof Location) {
return;
}
$widget->addFields([
//'addr1' => [
// 'label' => 'Address Line 1',
// 'type' => 'datepicker'
//]
]);
//$widget->removeField('surname');
});
\Event::listen('backend.menu.extendItems', function ($manager) {
$manager->removeMainMenuItem('Offline.OpeningHours', 'opening-hours-main');
});
\Event::listen('backend.page.beforeDisplay', function ($controller, $action, $parameters) {
if (!($controller instanceof Locations)) {
return;
}
if ($action === 'create') {
\BackendMenu::setContext('Gigafeed.Locations', 'locations', 'add_location');
} else {
\BackendMenu::setContext('Gigafeed.Locations', 'locations', 'locations');
}
});
}
/**
* Registers any front-end components implemented in this plugin.
*
* @return array
*/
public function registerComponents()
{
return []; // Remove this line to activate
return [
'Gigafeed\Locations\Components\MyComponent' => 'myComponent',
];
}
/**
* Registers any back-end permissions used by this plugin.
*
* @return array
*/
public function registerPermissions()
{
return []; // Remove this line to activate
return [
'gigafeed.locations.some_permission' => [
'tab' => 'Locations',
'label' => 'Some permission'
],
];
}
/**
* Registers back-end navigation items for this plugin.
*
* @return array
*/
public function registerNavigation()
{
return [
'locations' => [
'label' => 'Locations',
'url' => Backend::url('gigafeed/locations/locations'),
'icon' => 'icon-map',
'permissions' => ['gigafeed.locations.*'],
'order' => 500,
'sideMenu' => [
'add_location' => [
'label' => 'Add Locations',
'icon' => 'icon-plus',
'url' => Backend::url('offline/openinghours/locations/create'),
],
'locations' => [
'label' => 'Locations',
'icon' => 'icon-map',
'url' => Backend::url('gigafeed/locations/locations'),
],
]
],
];
}
}