Relationships::render()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php namespace Bedard\Shop\FormWidgets;
2
3
use Backend\Classes\FormWidgetBase;
4
5
/**
6
 * Relationships Form Widget.
7
 */
8
class Relationships extends FormWidgetBase
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13
    protected $defaultAlias = 'bedard_shop_relationships';
14
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function render()
19
    {
20
        $this->prepareVars();
21
22
        return $this->makePartial('relationships');
23
    }
24
25
    /**
26
     * Prepares the form widget view data.
27
     */
28
    public function prepareVars()
29
    {
30
        $this->vars['name'] = $this->formField->getName();
31
        $this->vars['value'] = $this->getLoadValue();
32
        $this->vars['model'] = $this->model;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function loadAssets()
39
    {
40
        $this->addJs('/plugins/bedard/shop/assets/dist/vendor.min.js', 'Bedard.Shop');
41
        $this->addJs('/plugins/bedard/shop/assets/dist/relationships.min.js', 'Bedard.Shop');
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getSaveValue($value)
48
    {
49
        $value = json_decode($value, true);
50
        $value['relationships'] = array_filter($value['relationships']);
51
52
        return $value['relationships'];
53
    }
54
}
55