|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Formularium\Frontend\Bulma\Renderable; |
|
4
|
|
|
|
|
5
|
|
|
use Formularium\Datatype; |
|
6
|
|
|
use Formularium\Datatype\Datatype_file; |
|
7
|
|
|
use Formularium\Field; |
|
8
|
|
|
use Formularium\Frontend\Bulma\RenderableBulmaTrait; |
|
9
|
|
|
use Formularium\Frontend\HTML\Framework; |
|
10
|
|
|
use Formularium\Frontend\HTML\Renderable; |
|
11
|
|
|
use Formularium\HTMLElement; |
|
12
|
|
|
|
|
13
|
|
|
class Renderable_file extends Renderable |
|
14
|
|
|
{ |
|
15
|
|
|
use RenderableBulmaTrait; |
|
16
|
|
|
|
|
17
|
|
|
public function viewable($value, Field $field, HTMLElement $previous): HTMLElement |
|
18
|
|
|
{ |
|
19
|
|
|
return $previous; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function _editable($value, Field $field, HTMLElement $previous): HTMLElement |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
$extensions = $field->getExtensions(); |
|
25
|
|
|
$validators = $field->getValidators(); |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
$input = $previous->get('input')[0]; |
|
28
|
|
|
$input->addAttribute('class', 'file-input'); |
|
29
|
|
|
|
|
30
|
|
|
$content = HTMLElement::factory( |
|
31
|
|
|
'div', |
|
32
|
|
|
['class' => "file has-name"], |
|
33
|
|
|
[ |
|
34
|
|
|
HTMLElement::factory( |
|
35
|
|
|
'label', |
|
36
|
|
|
['class' => "file-label"], |
|
37
|
|
|
[ |
|
38
|
|
|
$input, |
|
39
|
|
|
HTMLElement::factory( |
|
40
|
|
|
'span', |
|
41
|
|
|
['class' => "file-cta"], |
|
42
|
|
|
[ |
|
43
|
|
|
HTMLElement::factory( |
|
44
|
|
|
'span', |
|
45
|
|
|
['class' => "file-icon"], |
|
46
|
|
|
HTMLElement::factory( |
|
47
|
|
|
'i', |
|
48
|
|
|
[ 'class' => "fas fa-upload" ] |
|
49
|
|
|
) |
|
50
|
|
|
), |
|
51
|
|
|
HTMLElement::factory( |
|
52
|
|
|
'span', |
|
53
|
|
|
['class' => "file-label"], |
|
54
|
|
|
$extensions[Renderable::COMMENT] ?? 'Pick file or drag-drop' |
|
55
|
|
|
), |
|
56
|
|
|
] |
|
57
|
|
|
), |
|
58
|
|
|
HTMLElement::factory( |
|
59
|
|
|
'span', |
|
60
|
|
|
['class' => "file-name"], |
|
61
|
|
|
'' // TODO |
|
62
|
|
|
) |
|
63
|
|
|
] |
|
64
|
|
|
), |
|
65
|
|
|
HTMLElement::factory( |
|
66
|
|
|
'label', |
|
67
|
|
|
['class' => "formularium-label"], |
|
68
|
|
|
$extensions[Renderable::LABEL] ?? '' |
|
69
|
|
|
) |
|
70
|
|
|
] |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
|
|
return $content; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.