Passed
Pull Request — 2.x (#1360)
by Harings
14:11
created

TwillFormComponent   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 16
c 3
b 0
f 0
dl 0
loc 29
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 2
1
<?php
2
3
namespace A17\Twill\View\Components;
4
5
use Illuminate\Support\Facades\View;
6
use Illuminate\View\Component;
7
8
abstract class TwillFormComponent extends Component
9
{
10
    public $name;
11
    /**
12
     * @var \A17\Twill\Models\Model | null
13
     */
14
    public $item;
15
    public $label;
16
    public $form_fields;
17
    public $renderForBlocks;
18
    public $renderForModal;
19
20
    public function __construct(
21
        $name,
22
        $label,
23
        $renderForBlocks = false,
24
        $renderForModal = false
25
    ) {
26
        // This can be null. In that case the field might be used outside of a form and we have no shared $form.
27
        $form = View::shared("form");
28
        $this->renderForBlocks = $renderForBlocks;
29
        $this->item = $form['item'] ?? null;
30
        $this->form_fields = $form['form_fields'] ?? [];
31
        $this->name = $name;
32
        $this->label = $label;
33
34
        $shared = View::shared('TwillUntilConsumed', []);
35
        foreach ($shared as $key => $value) {
36
            $this->{$key} = $value;
37
        }
38
    }
39
}
40