-
Notifications
You must be signed in to change notification settings - Fork 1
/
Extension.php
executable file
·126 lines (97 loc) · 3.53 KB
/
Extension.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
<?php
namespace CupNoodles\OrderMenuEdit;
use System\Classes\BaseExtension;
// Admin-UI
use Event;
use Admin\Models\Menus_model;
use Admin\Widgets\Form;
use Admin\Widgets\Toolbar;
use Admin\Models\Orders_model;
use Admin\Classes\AdminController;
use Admin\Controllers\Orders;
use Igniter\Cart\Classes\CartManager;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\DB;
/**
* Butcher Extension Information File
*/
class Extension extends BaseExtension
{
/**
* Returns information about this extension.
*
* @return array
*/
public function extensionMeta()
{
return [
'name' => 'OrderMenuEdit',
'author' => 'CupNoodles',
'description' => 'Edit Order Menu Items in admin panel.',
'icon' => 'fa-edit',
'version' => '1.0.0'
];
}
/**
* Boot method, called right before the request route.
*
* @return void
*/
public function boot()
{
// Push extension views into $partialPath since this isn't a formwidget
AdminController::extend(function ($controller) {
if( in_array('~/app/admin/views/orders', $controller->partialPath)){
array_unshift($controller->partialPath, 'extensions/cupnoodles/ordermenuedit/views/');
array_unshift($controller->viewPath, 'extensions/cupnoodles/ordermenuedit/views/orders');
}
// if priceByWeight is installed, you may get a mild race condition on these partialPaths (pricebyweight also has a views/orders/form/order_menu.blade.php)
if (($key = array_search('~/extensions/cupnoodles/pricebyweight/views', $controller->partialPath)) !== false) {
unset($controller->partialPath[$key]);
}
if (($key = array_search('~/extensions/cupnoodles/pricebyweight/views/orders', $controller->viewPath)) !== false) {
unset($controller->viewPath[$key]);
}
});
// Enable save buttons on Order View
Event::listen('admin.form.extendFieldsBefore', function (Form $form) {
if ($form->model instanceof Orders_model) {
Event::listen('admin.toolbar.extendButtons', function (Toolbar $toolbar) {
$toolbar->buttons['save']['context'][] = 'edit';
$toolbar->buttons['saveClose']['context'][] = 'edit';
});
}
});
// Change the edit link on Orders List View to cupnoodles/ordermenuedit/edit/{id} so that the form submits to the extended controller
Orders::extend(function ($controller){
if($controller->listConfig['list']['model'] == 'Admin\Models\Orders_model'){
$controller->listConfig['list']['configFile'] = 'extensions/cupnoodles/ordermenuedit/models/config/orders_model';
}
});
}
/**
* Registers any front-end components implemented in this extension.
*
* @return array
*/
public function registerComponents()
{
}
/**
* Registers any admin permissions used by this extension.
*
* @return array
*/
public function registerPermissions()
{
return [
'Admin.UnitsOfMeasure' => [
'label' => 'cupnoodles.ordermenuedit::default.permissions',
'group' => 'admin::lang.permissions.name',
],
];
}
public function registerNavigation()
{
}
}