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 parent::getBaseCpPath() . '/providers/' . Craft::$app->getRequest()->getSegment(3); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @inheritdoc |
81
|
|
|
*/ |
82
|
|
|
protected function getBaseCpProvidersPath(): string |
83
|
|
|
{ |
84
|
|
|
return parent::getBaseCpPath() . '/providers'; |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
protected function getBaseActionPath(): string |
91
|
|
|
{ |
92
|
|
|
return parent::getBaseActionPath() . '/providers'; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
protected function getBaseCpPath(): string |
99
|
|
|
{ |
100
|
|
|
return parent::getBaseCpPath() . '/providers'; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/******************************************* |
104
|
|
|
* VARIABLES |
105
|
|
|
*******************************************/ |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Set base variables used to generate template views |
109
|
|
|
* |
110
|
|
|
* @param array $variables |
111
|
|
|
*/ |
112
|
|
|
protected function baseVariables(array &$variables = []) |
113
|
|
|
{ |
114
|
|
|
parent::baseVariables($variables); |
115
|
|
|
|
116
|
|
|
// Page title |
117
|
|
|
$variables['title'] .= ': ' . Craft::t('patron', "Providers"); |
118
|
|
|
|
119
|
|
|
// Breadcrumbs |
120
|
|
|
$variables['crumbs'][] = [ |
121
|
|
|
'label' => Craft::t('patron', "Providers"), |
122
|
|
|
'url' => UrlHelper::url(Patron::getInstance()->getUniqueId() . '/providers') |
123
|
|
|
]; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param array $variables |
128
|
|
|
*/ |
129
|
|
|
protected function insertVariables(array &$variables) |
130
|
|
|
{ |
131
|
|
|
// Apply base view variables |
132
|
|
|
$this->baseVariables($variables); |
133
|
|
|
|
134
|
|
|
// Set the "Continue Editing" URL |
135
|
|
|
$variables['continueEditingUrl'] = $this->getBaseContinueEditingUrl('/{id}'); |
136
|
|
|
|
137
|
|
|
// Append title |
138
|
|
|
$variables['title'] .= ' - ' . Craft::t('patron', 'New'); |
139
|
|
|
|
140
|
|
|
// Breadcrumbs |
141
|
|
|
$variables['crumbs'][] = [ |
142
|
|
|
'label' => Craft::t('patron', 'New'), |
143
|
|
|
'url' => UrlHelper::url($variables['baseCpPath'] . '/new') |
144
|
|
|
]; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/******************************************* |
148
|
|
|
* UPDATE VARIABLES |
149
|
|
|
*******************************************/ |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param array $variables |
153
|
|
|
* @param Provider $provider |
154
|
|
|
* @throws \ReflectionException |
155
|
|
|
*/ |
156
|
|
|
protected function updateVariables(array &$variables, Provider $provider) |
157
|
|
|
{ |
158
|
|
|
// Apply base view variables |
159
|
|
|
$this->baseVariables($variables); |
160
|
|
|
|
161
|
|
|
// Set the "Continue Editing" URL |
162
|
|
|
$variables['continueEditingUrl'] = $this->getBaseContinueEditingUrl('/' . $provider->getId()); |
163
|
|
|
$variables['baseCpProvidersPath'] = $this->getBaseCpProvidersPath(); |
164
|
|
|
$variables['baseCpProviderPath'] = $this->getBaseCpProviderPath(); |
165
|
|
|
|
166
|
|
|
// Append title |
167
|
|
|
$variables['title'] .= ' - ' . $provider->getDisplayName(); |
168
|
|
|
|
169
|
|
|
// Breadcrumbs |
170
|
|
|
$variables['crumbs'][] = [ |
171
|
|
|
'label' => $provider->getDisplayName(), |
172
|
|
|
'url' => UrlHelper::url( |
173
|
|
|
Patron::getInstance()->getUniqueId() . '/providers/' . $provider->getId() |
174
|
|
|
) |
175
|
|
|
]; |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.