1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SleepingOwl\Admin\Form; |
4
|
|
|
|
5
|
|
|
use SleepingOwl\Admin\Form\Card\Body; |
6
|
|
|
use SleepingOwl\Admin\Form\Card\Footer; |
7
|
|
|
use SleepingOwl\Admin\Form\Card\Header; |
8
|
|
|
use SleepingOwl\Admin\Form\Element\Html; |
9
|
|
|
use SleepingOwl\Admin\Traits\CardControl; |
10
|
|
|
use SleepingOwl\Admin\Contracts\Form\FormElementInterface; |
11
|
|
|
|
12
|
|
|
class FormCard extends FormDefault |
13
|
|
|
{ |
14
|
|
|
use CardControl; |
15
|
|
|
|
16
|
|
|
const POSITION_HEADER = 'header'; |
17
|
|
|
const POSITION_BODY = 'body'; |
18
|
|
|
const POSITION_FOOTER = 'footer'; |
19
|
|
|
|
20
|
|
|
// const SEPARATOR = '<hr class="panel-wide" />'; |
21
|
|
|
const SEPARATOR = ''; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $view = 'form.card'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* FormCard constructor. |
30
|
|
|
* |
31
|
|
|
* @param array $elements |
32
|
|
|
*/ |
33
|
|
|
public function __construct(array $elements = []) |
34
|
|
|
{ |
35
|
|
|
parent::__construct($elements); |
36
|
|
|
|
37
|
|
|
$this->setCardClass('card'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Initialize form. |
42
|
|
|
*/ |
43
|
|
|
public function initialize() |
44
|
|
|
{ |
45
|
|
|
$this->getButtons()->setHtmlAttribute('class', 'card-footer'); |
46
|
|
|
|
47
|
|
|
$this->setHtmlAttribute('class', 'card '.$this->getCardClass()); |
48
|
|
|
|
49
|
|
|
parent::initialize(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param array|FormElementInterface $items |
54
|
|
|
* |
55
|
|
|
* @return $this |
56
|
|
|
*/ |
57
|
|
|
public function setItems($items) |
58
|
|
|
{ |
59
|
|
|
if (! is_array($items)) { |
60
|
|
|
$items = func_get_args(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$this->addBody($items); |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param FormElementInterface $item |
70
|
|
|
* |
71
|
|
|
* @return $this |
72
|
|
|
*/ |
73
|
|
|
public function addItem($item) |
74
|
|
|
{ |
75
|
|
|
if ($part = $this->getElements()->last()) { |
76
|
|
|
$part->addElement($item); |
77
|
|
|
} else { |
78
|
|
|
$this->addBody($item); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param array|FormElementInterface $items |
86
|
|
|
* |
87
|
|
|
* @return $this |
88
|
|
|
*/ |
89
|
|
|
public function addHeader($items) |
90
|
|
|
{ |
91
|
|
|
if (! is_array($items)) { |
92
|
|
|
$items = func_get_args(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$this->addElement(new Header($items)); |
96
|
|
|
|
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param array|FormElementInterface $items |
102
|
|
|
* |
103
|
|
|
* @return $this |
104
|
|
|
*/ |
105
|
|
|
public function addBody($items) |
106
|
|
|
{ |
107
|
|
|
if (! is_array($items)) { |
108
|
|
|
$items = func_get_args(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$class = $this->getElements()->last(); |
112
|
|
|
if (is_object($class) && get_class($class) === Body::class) { |
113
|
|
|
$this->addElement(new Html('<hr />')); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$this->addElement(new Body($items)); |
117
|
|
|
|
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param array|FormElementInterface $items |
123
|
|
|
* |
124
|
|
|
* @return $this |
125
|
|
|
*/ |
126
|
|
|
public function addFooter($items) |
127
|
|
|
{ |
128
|
|
|
if (! is_array($items)) { |
129
|
|
|
$items = func_get_args(); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
$this->addElement(new Footer($items)); |
133
|
|
|
|
134
|
|
|
return $this; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|