|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Formularium\Frontend\Buefy\Renderable; |
|
4
|
|
|
|
|
5
|
|
|
use Formularium\Datatype; |
|
6
|
|
|
use Formularium\Datatype\Datatype_file; |
|
7
|
|
|
use Formularium\Field; |
|
8
|
|
|
use Formularium\Frontend\HTML\Renderable\Renderable_file as HTMLRenderable_file; |
|
9
|
|
|
use Formularium\HTMLElement; |
|
10
|
|
|
use Formularium\Renderable; |
|
11
|
|
|
|
|
12
|
|
|
class Renderable_file extends \Formularium\Renderable |
|
13
|
|
|
{ |
|
14
|
|
|
use \Formularium\Frontend\HTML\RenderableViewableTrait; |
|
15
|
|
|
|
|
16
|
|
|
public function editable($value, Field $field, HTMLElement $previous): HTMLElement |
|
17
|
|
|
{ |
|
18
|
|
|
$extensions = $field->getExtensions(); |
|
19
|
|
|
$validators = $field->getValidators(); |
|
20
|
|
|
|
|
21
|
|
|
$inputAtts = [ |
|
22
|
|
|
'name' => $field->getName(), |
|
23
|
|
|
'v-model' => $field->getName(), |
|
24
|
|
|
'drag-drop' => '' |
|
25
|
|
|
]; |
|
26
|
|
|
if ($extensions[HTMLRenderable_file::ACCEPT] ?? false) { |
|
27
|
|
|
if (is_array($extensions[HTMLRenderable_file::ACCEPT])) { |
|
28
|
|
|
$accept = join(',', $extensions[HTMLRenderable_file::ACCEPT]); |
|
29
|
|
|
} else { |
|
30
|
|
|
$accept = $extensions[HTMLRenderable_file::ACCEPT]; |
|
31
|
|
|
} |
|
32
|
|
|
$inputAtts['accept'] = htmlspecialchars($accept); |
|
33
|
|
|
} |
|
34
|
|
|
if ($validators[Datatype::REQUIRED] ?? false) { |
|
35
|
|
|
$inputAtts['required'] = 'required'; |
|
36
|
|
|
} |
|
37
|
|
|
if ($validators[Datatype_file::MAX_SIZE] ?? false) { |
|
38
|
|
|
$inputAtts['data-max-size'] = $validators[Datatype_file::MAX_SIZE]; |
|
39
|
|
|
} |
|
40
|
|
|
foreach ([static::DISABLED, static::READONLY] as $v) { |
|
41
|
|
|
if ($field->getExtension($v, false)) { |
|
42
|
|
|
$inputAtts[$v] = true; |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$container = HTMLElement::factory( |
|
47
|
|
|
'b-field', |
|
48
|
|
|
[], |
|
49
|
|
|
HTMLElement::factory( |
|
50
|
|
|
'b-upload', |
|
51
|
|
|
$inputAtts, |
|
52
|
|
|
HTMLElement::factory( |
|
53
|
|
|
'section', |
|
54
|
|
|
['class' => 'section'], |
|
55
|
|
|
HTMLElement::factory( |
|
56
|
|
|
'div', |
|
57
|
|
|
['class' => "content has-text-centered"], |
|
58
|
|
|
[ |
|
59
|
|
|
HTMLElement::factory( |
|
60
|
|
|
'p', |
|
61
|
|
|
[], |
|
62
|
|
|
HTMLElement::factory( |
|
63
|
|
|
'b-icon', |
|
64
|
|
|
[ 'icon' => "upload", 'size' => "is-large" ] |
|
65
|
|
|
) |
|
66
|
|
|
), |
|
67
|
|
|
HTMLElement::factory( |
|
68
|
|
|
'p', |
|
69
|
|
|
[ 'class' => 'formularium-label'], |
|
70
|
|
|
$extensions[Renderable::LABEL] ?? '' |
|
71
|
|
|
) |
|
72
|
|
|
] |
|
73
|
|
|
) |
|
74
|
|
|
) |
|
75
|
|
|
) |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
return $container; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|