1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Formularium\Frontend\Bootstrap; |
4
|
|
|
|
5
|
|
|
use Formularium\Field; |
6
|
|
|
use Formularium\HTMLNode; |
7
|
|
|
use Formularium\Frontend\HTML\Renderable; |
8
|
|
|
|
9
|
|
|
trait RenderableBootstrapWrapperTrait |
10
|
|
|
{ |
11
|
|
|
public function wrapper($value, Field $field, HTMLNode $previous): HTMLNode |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
/** @var HTMLNode $base */ |
14
|
|
|
$previous->addAttributes([ |
15
|
|
|
'class' => "form-group", |
16
|
|
|
'data-attribute' => $field->getName(), |
17
|
|
|
'data-datatype' => $field->getDatatype()->getName(), |
18
|
|
|
'data-basetype' => $field->getDatatype()->getBasetype() |
19
|
|
|
]); |
20
|
|
|
return $previous; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* |
25
|
|
|
* |
26
|
|
|
* @param mixed $value |
27
|
|
|
* @param Field $field |
28
|
|
|
* @param HTMLNode $previous |
29
|
|
|
* @return HTMLNode |
30
|
|
|
*/ |
31
|
|
|
public function bootstrapify($value, Field $field, HTMLNode $previous, $tag = 'input'): HTMLNode |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
// add extra classes |
34
|
|
|
$input = $previous->get($tag)[0]; |
35
|
|
|
$input->addAttributes([ |
36
|
|
|
'class' => 'form-control', |
37
|
|
|
]); |
38
|
|
|
$comment = $previous->get('.formularium-comment'); |
39
|
|
|
if (!empty($comment)) { |
40
|
|
|
$comment[0]->setTag('small')->addAttributes([ |
41
|
|
|
'class' => 'form-text text-muted', |
42
|
|
|
]); |
43
|
|
|
} |
44
|
|
|
$size = $field->getRenderable(Renderable::SIZE, ''); |
45
|
|
|
switch ($size) { |
46
|
|
|
case Renderable::SIZE_LARGE: |
47
|
|
|
$input->addAttribute('class', 'form-control-lg'); |
48
|
|
|
break; |
49
|
|
|
case Renderable::SIZE_SMALL: |
50
|
|
|
$input->addAttribute('class', 'form-control-sm'); |
51
|
|
|
break; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$icon = $field->getRenderable(Renderable::ICON, ''); |
55
|
|
|
if ($icon) { |
56
|
|
|
$iconData = []; |
57
|
|
|
$iconPack = $field->getRenderable(Renderable::ICON_PACK, ''); |
58
|
|
|
if ($iconPack) { |
59
|
|
|
$iconData[] = $iconPack; |
60
|
|
|
} |
61
|
|
|
$iconData[] = $icon; |
62
|
|
|
$group = HTMLNode::factory( |
63
|
|
|
'div', |
64
|
|
|
[ 'class' => "input-group mb-3" ], |
65
|
|
|
[ |
66
|
|
|
HTMLNode::factory( |
67
|
|
|
'div', |
68
|
|
|
[ 'class' => "input-group-prepend" ], |
69
|
|
|
HTMLNode::factory( |
70
|
|
|
'span', |
71
|
|
|
[ 'class' => "input-group-text" ], |
72
|
|
|
HTMLNode::factory( |
73
|
|
|
'i', |
74
|
|
|
[ 'class' => $iconData ], |
75
|
|
|
[] |
76
|
|
|
) |
77
|
|
|
) |
78
|
|
|
), |
79
|
|
|
clone $input |
80
|
|
|
] |
81
|
|
|
); |
82
|
|
|
$input->replace($group); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return $previous; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.