Completed
Push — master ( 3fed4b...dafce2 )
by Nate
16:31 queued 05:53
created

Settings::alterStateColumn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
crap 2
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\services;
10
11
use Craft;
12
use flipbox\organizations\migrations\AlterOrganizationStates;
13
use flipbox\organizations\models\Settings as SettingsModel;
14
use flipbox\organizations\Organizations as OrganizationPlugin;
15
use yii\base\Component;
16
use yii\base\InvalidConfigException;
17
18
/**
19
 * @author Flipbox Factory <[email protected]>
20
 * @since 1.0.0
21
 */
22
class Settings extends Component
23
{
24
    /**
25
     * @param SettingsModel $settingsModel
26
     * @return bool
27
     * @throws \Throwable
28
     */
29
    public function save(SettingsModel $settingsModel)
30
    {
31
        $fieldLayout = $settingsModel->getFieldLayout();
32
33
        // Save field layout
34
        if (!Craft::$app->getFields()->saveLayout($fieldLayout)) {
35
            throw new InvalidConfigException("Unable to save field layout");
36
        }
37
38
        return Craft::$app->getPlugins()->savePluginSettings(
39
            OrganizationPlugin::getInstance(),
40
            $settingsModel->toArray()
41
        );
42
    }
43
}
44