Completed
Push — master ( 3faafa...2b244d )
by Song
02:59
created

Row::getFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Form;
4
5
use Encore\Admin\Form;
6
use Illuminate\Contracts\Support\Renderable;
7
8
class Row implements Renderable
9
{
10
    /**
11
     * Callback for add field to current row.s.
12
     *
13
     * @var \Closure
14
     */
15
    protected $callback;
16
17
    /**
18
     * Parent form.
19
     *
20
     * @var Form
21
     */
22
    protected $form;
23
24
    /**
25
     * Fields in this row.
26
     *
27
     * @var array
28
     */
29
    protected $fields = [];
30
31
    /**
32
     * Default field width for appended field.
33
     *
34
     * @var int
35
     */
36
    protected $defaultFieldWidth = 12;
37
38
    /**
39
     * Row constructor.
40
     *
41
     * @param \Closure $callback
42
     * @param Form     $form
43
     */
44
    public function __construct(\Closure $callback, Form $form)
45
    {
46
        $this->callback = $callback;
47
48
        $this->form = $form;
49
50
        call_user_func($this->callback, $this);
51
    }
52
53
    /**
54
     * Get fields of this row.
55
     *
56
     * @return array
57
     */
58
    public function getFields()
59
    {
60
        return $this->fields;
61
    }
62
63
    /**
64
     * Set width for a incomming field.
65
     *
66
     * @param int $width
67
     *
68
     * @return $this
69
     */
70
    public function width($width = 12)
71
    {
72
        $this->defaultFieldWidth = $width;
73
74
        return $this;
75
    }
76
77
    /**
78
     * Render the row.
79
     *
80
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
81
     */
82
    public function render()
83
    {
84
        return view('admin::form.row', ['fields' => $this->fields]);
0 ignored issues
show
Bug Compatibility introduced by
The expression view('admin::form.row', ...ds' => $this->fields)); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 84 which is incompatible with the return type declared by the interface Illuminate\Contracts\Support\Renderable::render of type string.
Loading history...
85
    }
86
87
    /**
88
     * Add field.
89
     *
90
     * @param string $method
91
     * @param array  $arguments
92
     *
93
     * @return Field|void
94
     */
95
    public function __call($method, $arguments)
96
    {
97
        $field = $this->form->__call($method, $arguments);
98
99
        $field->disableHorizontal();
100
101
        $this->fields[] = [
102
            'width'   => $this->defaultFieldWidth,
103
            'element' => $field,
104
        ];
105
106
        return $field;
107
    }
108
}
109