Completed
Push — master ( e45dbf...3a73d5 )
by Nate
05:43 queued 04:08
created

SettingsController::verbs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/patron/license
6
 * @link       https://www.flipboxfactory.com/software/patron/
7
 */
8
9
namespace flipbox\patron\cp\controllers;
10
11
use Craft;
12
use craft\helpers\ArrayHelper;
13
use flipbox\patron\cp\actions\settings\Update;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class SettingsController extends AbstractController
20
{
21
    /**
22
     * @return array
23
     */
24
    public function behaviors()
25
    {
26
        return ArrayHelper::merge(
27
            parent::behaviors(),
28
            [
29
                'error' => [
30
                    'default' => 'save'
31
                ],
32
                'redirect' => [
33
                    'only' => ['save'],
34
                    'actions' => [
35
                        'save' => [200]
36
                    ]
37
                ],
38
                'flash' => [
39
                    'actions' => [
40
                        'save' => [
41
                            200 => Craft::t('patron', "Settings successfully updated."),
42
                            401 => Craft::t('patron', "Failed to update settings.")
43
                        ]
44
                    ]
45
                ]
46
            ]
47
        );
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    protected function verbs(): array
54
    {
55
        return [
56
            'save' => ['post', 'put']
57
        ];
58
    }
59
60
    /**
61
     * @return mixed
62
     * @throws \yii\base\InvalidConfigException
63
     */
64
    public function actionSave()
65
    {
66
        /** @var Update $action */
67
        $action = Craft::createObject([
68
            'class' => Update::class,
69
            'checkAccess' => [$this, 'checkUpdateAccess']
70
        ], [
71
            'update',
72
            $this
73
        ]);
74
75
        return $action->runWithParams([]);
76
    }
77
78
    /**
79
     * @return bool
80
     * @throws \yii\web\ForbiddenHttpException
81
     */
82
    public function checkUpdateAccess(): bool
83
    {
84
        return $this->checkAdminAccess();
85
    }
86
}
87