SiteSettings::behaviors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 9
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
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\organization\models;
10
11
use craft\base\Model;
12
use craft\behaviors\FieldLayoutBehavior;
13
use craft\models\FieldLayout;
14
use flipbox\organization\elements\Organization as OrganizationElement;
15
16
/**
17
 * @author Flipbox Factory <[email protected]>
18
 * @since 1.0.0
19
 */
20
class SiteSettings extends Model
21
{
22
23
    /**
24
     * @var boolean Has URLs
25
     */
26
    public $siteId;
27
28
    /**
29
     * @var boolean Has URLs
30
     */
31
    public $hasUrls = true;
32
33
    /**
34
     * @var string URL format
35
     */
36
    public $uriFormat;
37
38
    /**
39
     * @var string Template
40
     */
41
    public $template;
42
43
    /**
44
     * @var integer Default Layout Id
45
     */
46
    public $fieldLayoutId;
47
48
    // Public Methods
49
    // =========================================================================
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public function behaviors()
55
    {
56
        return [
57
            'fieldLayout' => [
58
                'class' => FieldLayoutBehavior::class,
59
                'elementType' => OrganizationElement::class
60
            ]
61
        ];
62
    }
63
64
    /**
65
     * Returns the owner's field layout.
66
     *
67
     * @return FieldLayout
68
     */
69
    public function getFieldLayout(): FieldLayout
70
    {
71
        return $this->getFieldLayoutBehavior()->getFieldLayout();
72
    }
73
74
    /**
75
     * Sets the owner's field layout.
76
     *
77
     * @param FieldLayout $fieldLayout
78
     *
79
     * @return void
80
     */
81
    public function setFieldLayout(FieldLayout $fieldLayout)
82
    {
83
        $fieldLayout->type = OrganizationElement::class;
84
        $this->getFieldLayoutBehavior()->setFieldLayout($fieldLayout);
85
    }
86
87
    /**
88
     * @return null|\yii\base\Behavior|FieldLayoutBehavior
89
     */
90
    private function getFieldLayoutBehavior()
91
    {
92
        $this->ensureBehaviors();
93
        return $this->getBehavior('fieldLayout');
94
    }
95
}
96