|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
|
5
|
|
|
* @license https://flipboxfactory.com/software/organization/license |
|
6
|
|
|
* @link https://www.flipboxfactory.com/software/organization/ |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace flipbox\organizations\cp\controllers\settings; |
|
10
|
|
|
|
|
11
|
|
|
use Craft; |
|
12
|
|
|
use craft\helpers\ArrayHelper; |
|
13
|
|
|
use flipbox\organizations\cp\actions\general\Update; |
|
14
|
|
|
use flipbox\organizations\cp\controllers\AbstractController; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author Flipbox Factory <[email protected]> |
|
18
|
|
|
* @since 1.0.0 |
|
19
|
|
|
*/ |
|
20
|
|
|
class GeneralController extends AbstractController |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @return array |
|
24
|
|
|
*/ |
|
25
|
|
|
public function behaviors() |
|
26
|
|
|
{ |
|
27
|
|
|
return ArrayHelper::merge( |
|
28
|
|
|
parent::behaviors(), |
|
29
|
|
|
[ |
|
30
|
|
|
'error' => [ |
|
31
|
|
|
'default' => 'save' |
|
32
|
|
|
], |
|
33
|
|
|
'redirect' => [ |
|
34
|
|
|
'only' => ['save'], |
|
35
|
|
|
'actions' => [ |
|
36
|
|
|
'save' => [200] |
|
37
|
|
|
] |
|
38
|
|
|
], |
|
39
|
|
|
'flash' => [ |
|
40
|
|
|
'actions' => [ |
|
41
|
|
|
'save' => [ |
|
42
|
|
|
200 => Craft::t('organizations', "Settings successfully updated."), |
|
43
|
|
|
401 => Craft::t('organizations', "Failed to update settings.") |
|
44
|
|
|
] |
|
45
|
|
|
] |
|
46
|
|
|
] |
|
47
|
|
|
] |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function verbs(): array |
|
55
|
|
|
{ |
|
56
|
|
|
return [ |
|
57
|
|
|
'save' => ['post', 'put'] |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return mixed |
|
63
|
|
|
* @throws \yii\base\InvalidConfigException |
|
64
|
|
|
*/ |
|
65
|
|
|
public function actionSave() |
|
66
|
|
|
{ |
|
67
|
|
|
/** @var Update $action */ |
|
68
|
|
|
$action = Craft::createObject([ |
|
69
|
|
|
'class' => Update::class, |
|
70
|
|
|
'checkAccess' => [$this, 'checkUpdateAccess'] |
|
71
|
|
|
], [ |
|
72
|
|
|
'update', |
|
73
|
|
|
$this |
|
74
|
|
|
]); |
|
75
|
|
|
|
|
76
|
|
|
return $action->runWithParams([]); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return bool |
|
81
|
|
|
*/ |
|
82
|
|
|
public function checkUpdateAccess(): bool |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->checkAdminAccess(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return bool |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function checkAdminAccess() |
|
91
|
|
|
{ |
|
92
|
|
|
$this->requireLogin(); |
|
93
|
|
|
return Craft::$app->getUser()->getIsAdmin(); |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: