Completed
Push — develop ( 2d4f17...d5975b )
by Nate
05:25
created

GeneralController::behaviors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 25
cp 0
rs 9.52
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/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\craft\hubspot\cp\controllers\settings;
10
11
use Craft;
12
use craft\helpers\ArrayHelper;
13
use flipbox\craft\hubspot\cp\actions\SaveSettings;
14
use flipbox\craft\hubspot\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' => 'settings'
32
                ],
33
                'redirect' => [
34
                    'only' => ['save'],
35
                    'actions' => [
36
                        'save' => [200]
37
                    ]
38
                ],
39
                'flash' => [
40
                    'actions' => [
41
                        'save' => [
42
                            200 => Craft::t('hubspot', "Settings successfully saved."),
43
                            400 => Craft::t('hubspot', "Failed to save settings.")
44
                        ]
45
                    ]
46
                ]
47
            ]
48
        );
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    protected function verbs(): array
55
    {
56
        return [
57
            'save' => ['post']
58
        ];
59
    }
60
61
    /**
62
     * @return mixed
63
     * @throws \yii\base\InvalidConfigException
64
     */
65
    public function actionSave()
66
    {
67
        /** @var SaveSettings $action */
68
        $action = Craft::createObject([
69
            'class' => SaveSettings::class
70
        ], [
71
            'save',
72
            $this
73
        ]);
74
75
        return $action->runWithParams([]);
76
    }
77
}
78