1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace flipbox\patron\cp\controllers\view\providers; |
4
|
|
|
|
5
|
|
|
use Craft; |
6
|
|
|
use craft\helpers\UrlHelper; |
7
|
|
|
use flipbox\patron\cp\Cp; |
8
|
|
|
use flipbox\patron\Patron; |
9
|
|
|
use flipbox\patron\records\Provider; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @property Cp $module |
13
|
|
|
*/ |
14
|
|
|
abstract class AbstractViewController extends \flipbox\patron\cp\controllers\view\AbstractViewController |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* The index view template path |
18
|
|
|
*/ |
19
|
|
|
const TEMPLATE_BASE = 'patron/_cp/provider'; |
20
|
|
|
|
21
|
|
|
/******************************************* |
22
|
|
|
* ENVIRONMENTS |
23
|
|
|
*******************************************/ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param Provider $provider |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
|
|
protected function availableEnvironments(Provider $provider): array |
30
|
|
|
{ |
31
|
|
|
$usedEnvironments = array_keys($provider->environments); |
32
|
|
|
$allEnvironments = Patron::getInstance()->getSettings()->getEnvironments(); |
33
|
|
|
|
34
|
|
|
return array_diff($allEnvironments, $usedEnvironments); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/******************************************* |
38
|
|
|
* TABS |
39
|
|
|
*******************************************/ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param Provider $provider |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
protected function getTabs(Provider $provider): array |
46
|
|
|
{ |
47
|
|
|
if ($provider->getId() === null) { |
48
|
|
|
return []; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$baseUrl = Craft::$app->getRequest()->getSegment(1) . '/' . |
52
|
|
|
Craft::$app->getRequest()->getSegment(2) . '/' . |
53
|
|
|
Craft::$app->getRequest()->getSegment(3); |
54
|
|
|
|
55
|
|
|
return [ |
56
|
|
|
'general' => [ |
57
|
|
|
'label' => Craft::t('patron', 'General'), |
58
|
|
|
'url' => UrlHelper::url($baseUrl . '/') |
59
|
|
|
], |
60
|
|
|
'tokens' => [ |
61
|
|
|
'label' => Craft::t('patron', 'Tokens'), |
62
|
|
|
'url' => UrlHelper::url($baseUrl . '/tokens') |
63
|
|
|
] |
64
|
|
|
]; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/******************************************* |
68
|
|
|
* PATHS |
69
|
|
|
*******************************************/ |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @inheritdoc |
73
|
|
|
*/ |
74
|
|
|
protected function getBaseCpProviderPath(): string |
75
|
|
|
{ |
76
|
|
|
return $this->getBaseCpPath() . '/' . Craft::$app->getRequest()->getSegment(3); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
protected function getBaseActionPath(): string |
83
|
|
|
{ |
84
|
|
|
return parent::getBaseActionPath() . '/providers'; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
protected function getBaseCpPath(): string |
91
|
|
|
{ |
92
|
|
|
return parent::getBaseCpPath() . '/providers'; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/******************************************* |
96
|
|
|
* VARIABLES |
97
|
|
|
*******************************************/ |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Set base variables used to generate template views |
101
|
|
|
* |
102
|
|
|
* @param array $variables |
103
|
|
|
*/ |
104
|
|
|
protected function baseVariables(array &$variables = []) |
105
|
|
|
{ |
106
|
|
|
parent::baseVariables($variables); |
107
|
|
|
|
108
|
|
|
// Page title |
109
|
|
|
$variables['title'] .= ': ' . Craft::t('patron', "Providers"); |
110
|
|
|
|
111
|
|
|
// Breadcrumbs |
112
|
|
|
$variables['crumbs'][] = [ |
113
|
|
|
'label' => Craft::t('patron', "Providers"), |
114
|
|
|
'url' => UrlHelper::url(Patron::getInstance()->getUniqueId() . '/providers') |
115
|
|
|
]; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param array $variables |
120
|
|
|
*/ |
121
|
|
|
protected function insertVariables(array &$variables) |
122
|
|
|
{ |
123
|
|
|
// apply base view variables |
124
|
|
|
$this->baseVariables($variables); |
125
|
|
|
|
126
|
|
|
// Set the "Continue Editing" URL |
127
|
|
|
$variables['continueEditingUrl'] = $this->getBaseContinueEditingUrl('/{id}'); |
128
|
|
|
|
129
|
|
|
// Append title |
130
|
|
|
$variables['title'] .= ' - ' . Craft::t('patron', 'New'); |
131
|
|
|
|
132
|
|
|
// Breadcrumbs |
133
|
|
|
$variables['crumbs'][] = [ |
134
|
|
|
'label' => Craft::t('patron', 'New'), |
135
|
|
|
'url' => UrlHelper::url($variables['baseCpPath'] . '/new') |
136
|
|
|
]; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/******************************************* |
140
|
|
|
* UPDATE VARIABLES |
141
|
|
|
*******************************************/ |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param array $variables |
145
|
|
|
* @param Provider $provider |
146
|
|
|
*/ |
147
|
|
|
protected function updateVariables(array &$variables, Provider $provider) |
148
|
|
|
{ |
149
|
|
|
// apply base view variables |
150
|
|
|
$this->baseVariables($variables); |
151
|
|
|
|
152
|
|
|
// Set the "Continue Editing" URL |
153
|
|
|
$variables['continueEditingUrl'] = $this->getBaseContinueEditingUrl('/' . $provider->getId()); |
154
|
|
|
$variables['baseCpProviderPath'] = $this->getBaseCpProviderPath(); |
155
|
|
|
|
156
|
|
|
// Append title |
157
|
|
|
$variables['title'] .= ' - ' . $provider->getDisplayName(); |
158
|
|
|
|
159
|
|
|
// Breadcrumbs |
160
|
|
|
$variables['crumbs'][] = [ |
161
|
|
|
'label' => $provider->getDisplayName(), |
162
|
|
|
'url' => UrlHelper::url( |
163
|
|
|
Patron::getInstance()->getUniqueId() . '/providers/' . $provider->getId() |
164
|
|
|
) |
165
|
|
|
]; |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|