Layout   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 7
dl 0
loc 26
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A save() 0 18 3
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\organization\modules\configuration\services;
10
11
use Craft;
12
use flipbox\organization\models\Settings;
13
use flipbox\organization\Organization as OrganizationPlugin;
14
use yii\base\Component;
15
use yii\base\InvalidConfigException;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class Layout extends Component
22
{
23
    /**
24
     * @param Settings $settingsModel
25
     * @return bool
26
     * @throws InvalidConfigException
27
     */
28
    public function save(Settings $settingsModel)
29
    {
30
        foreach ($settingsModel->getSites() as $siteSettings) {
31
            $fieldLayout = $siteSettings->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
            $siteSettings->fieldLayoutId = $fieldLayout->id;
39
        }
40
41
        return Craft::$app->getPlugins()->savePluginSettings(
42
            OrganizationPlugin::getInstance(),
43
            $settingsModel->toArray()
44
        );
45
    }
46
}
47