1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Formularium\Frontend\Bulma; |
4
|
|
|
|
5
|
|
|
use Formularium\Field; |
6
|
|
|
use Formularium\Frontend\HTML\Renderable; |
7
|
|
|
use Formularium\HTMLNode; |
8
|
|
|
|
9
|
|
|
trait RenderableBulmaInputTrait |
10
|
|
|
{ |
11
|
|
|
use RenderableBulmaTrait; |
12
|
|
|
|
13
|
|
|
public function viewable($value, Field $field, HTMLNode $previous): HTMLNode |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
return $previous; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Subcall of wrapper editable() from RenderableMaterializeTrait |
20
|
|
|
* |
21
|
|
|
* @param mixed $value |
22
|
|
|
* @param Field $field |
23
|
|
|
* @param HTMLNode $previous |
24
|
|
|
* @return HTMLNode |
25
|
|
|
*/ |
26
|
|
|
public function _editable($value, Field $field, HTMLNode $previous): HTMLNode |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
// add extra classes |
29
|
|
|
$input = $previous->get('input'); |
30
|
|
|
$input[0]->setAttributes([ |
31
|
|
|
'class' => 'input', |
32
|
|
|
]); |
33
|
|
|
$comment = $previous->get('.formularium-comment'); |
34
|
|
|
if (!empty($comment)) { |
35
|
|
|
$comment[0]->setTag('p')->addAttributes([ |
36
|
|
|
'class' => 'help', |
37
|
|
|
]); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$size = $field->getRenderable(Renderable::SIZE, ''); |
41
|
|
|
switch ($size) { |
42
|
|
|
case Renderable::SIZE_LARGE: |
43
|
|
|
$input[0]->addAttribute('class', 'is-large'); |
44
|
|
|
break; |
45
|
|
|
case Renderable::SIZE_SMALL: |
46
|
|
|
$input[0]->addAttribute('class', 'is-small'); |
47
|
|
|
break; |
48
|
|
|
} |
49
|
|
|
$icon = $field->getRenderable(Renderable::ICON, ''); |
50
|
|
|
if ($icon) { |
51
|
|
|
$iconData = []; |
52
|
|
|
$iconPack = $field->getRenderable(Renderable::ICON_PACK, ''); |
53
|
|
|
if ($iconPack) { |
54
|
|
|
$iconData[] = $iconPack; |
55
|
|
|
} |
56
|
|
|
$iconData[] = $icon; |
57
|
|
|
$iconElement = HTMLNode::factory( |
58
|
|
|
'span', |
59
|
|
|
[ 'class' => "icon is-small is-left" ], |
60
|
|
|
[ |
61
|
|
|
HTMLNode::factory( |
62
|
|
|
'i', |
63
|
|
|
[ 'class' => $iconData ], |
64
|
|
|
[] |
65
|
|
|
) |
66
|
|
|
] |
67
|
|
|
); |
68
|
|
|
$previous->addAttribute('class', 'has-icons-left'); |
69
|
|
|
$previous->appendContent($iconElement); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $previous; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.