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
|
|
|
/******************************************* |
23
|
|
|
* TABS |
24
|
|
|
*******************************************/ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param Provider $provider |
28
|
|
|
* @return array |
29
|
|
|
*/ |
30
|
|
|
protected function getTabs(Provider $provider): array |
31
|
|
|
{ |
32
|
|
|
if ($provider->getId() === null) { |
33
|
|
|
return []; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$baseUrl = Craft::$app->getRequest()->getSegment(1) . '/' . |
37
|
|
|
Craft::$app->getRequest()->getSegment(2) . '/' . |
38
|
|
|
Craft::$app->getRequest()->getSegment(3); |
39
|
|
|
|
40
|
|
|
return [ |
41
|
|
|
'general' => [ |
42
|
|
|
'label' => Craft::t('patron', 'General'), |
43
|
|
|
'url' => UrlHelper::url($baseUrl . '/') |
44
|
|
|
], |
45
|
|
|
'tokens' => [ |
46
|
|
|
'label' => Craft::t('patron', 'Tokens'), |
47
|
|
|
'url' => UrlHelper::url($baseUrl . '/tokens') |
48
|
|
|
] |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/******************************************* |
53
|
|
|
* PATHS |
54
|
|
|
*******************************************/ |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @inheritdoc |
58
|
|
|
*/ |
59
|
|
|
protected function getBaseCpProviderPath(): string |
60
|
|
|
{ |
61
|
|
|
return parent::getBaseCpPath() . '/providers/' . Craft::$app->getRequest()->getSegment(3); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @inheritdoc |
66
|
|
|
*/ |
67
|
|
|
protected function getBaseCpProvidersPath(): string |
68
|
|
|
{ |
69
|
|
|
return parent::getBaseCpPath() . '/providers'; |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
protected function getBaseActionPath(): string |
76
|
|
|
{ |
77
|
|
|
return parent::getBaseActionPath() . '/providers'; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
protected function getBaseCpPath(): string |
84
|
|
|
{ |
85
|
|
|
return parent::getBaseCpPath() . '/providers'; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/******************************************* |
89
|
|
|
* VARIABLES |
90
|
|
|
*******************************************/ |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Set base variables used to generate template views |
94
|
|
|
* |
95
|
|
|
* @param array $variables |
96
|
|
|
*/ |
97
|
|
|
protected function baseVariables(array &$variables = []) |
98
|
|
|
{ |
99
|
|
|
parent::baseVariables($variables); |
100
|
|
|
|
101
|
|
|
// Page title |
102
|
|
|
$variables['title'] .= ': ' . Craft::t('patron', "Providers"); |
103
|
|
|
|
104
|
|
|
// Breadcrumbs |
105
|
|
|
$variables['crumbs'][] = [ |
106
|
|
|
'label' => Craft::t('patron', "Providers"), |
107
|
|
|
'url' => UrlHelper::url(Patron::getInstance()->getUniqueId() . '/providers') |
108
|
|
|
]; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param array $variables |
113
|
|
|
*/ |
114
|
|
|
protected function insertVariables(array &$variables) |
115
|
|
|
{ |
116
|
|
|
// Apply base view variables |
117
|
|
|
$this->baseVariables($variables); |
118
|
|
|
|
119
|
|
|
// Set the "Continue Editing" URL |
120
|
|
|
$variables['continueEditingUrl'] = $this->getBaseContinueEditingUrl('/{id}'); |
121
|
|
|
|
122
|
|
|
// Append title |
123
|
|
|
$variables['title'] .= ' - ' . Craft::t('patron', 'New'); |
124
|
|
|
|
125
|
|
|
// Breadcrumbs |
126
|
|
|
$variables['crumbs'][] = [ |
127
|
|
|
'label' => Craft::t('patron', 'New'), |
128
|
|
|
'url' => UrlHelper::url($variables['baseCpPath'] . '/new') |
129
|
|
|
]; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/******************************************* |
133
|
|
|
* UPDATE VARIABLES |
134
|
|
|
*******************************************/ |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param array $variables |
138
|
|
|
* @param Provider $provider |
139
|
|
|
* @throws \ReflectionException |
140
|
|
|
*/ |
141
|
|
|
protected function updateVariables(array &$variables, Provider $provider) |
142
|
|
|
{ |
143
|
|
|
// Apply base view variables |
144
|
|
|
$this->baseVariables($variables); |
145
|
|
|
|
146
|
|
|
// Set the "Continue Editing" URL |
147
|
|
|
$variables['continueEditingUrl'] = $this->getBaseContinueEditingUrl('/' . $provider->getId()); |
148
|
|
|
$variables['baseCpProvidersPath'] = $this->getBaseCpProvidersPath(); |
149
|
|
|
$variables['baseCpProviderPath'] = $this->getBaseCpProviderPath(); |
150
|
|
|
|
151
|
|
|
$providerInfo = $provider->getInfo(); |
152
|
|
|
|
153
|
|
|
// Append title |
154
|
|
|
$variables['title'] .= ' - ' . ($providerInfo['name'] ?? ''); |
155
|
|
|
|
156
|
|
|
// Breadcrumbs |
157
|
|
|
$variables['crumbs'][] = [ |
158
|
|
|
'label' => $providerInfo['name'] ?? '', |
159
|
|
|
'url' => UrlHelper::url( |
160
|
|
|
Patron::getInstance()->getUniqueId() . '/providers/' . $provider->getId() |
161
|
|
|
) |
162
|
|
|
]; |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
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.