|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Formularium\Frontend\HTML; |
|
4
|
|
|
|
|
5
|
|
|
use Formularium\FrameworkComposer; |
|
6
|
|
|
use Formularium\HTMLNode; |
|
7
|
|
|
|
|
8
|
|
|
class Framework extends \Formularium\Framework |
|
9
|
|
|
{ |
|
10
|
|
|
public const SCHEMA_ITEMSCOPE = 'itemscope'; |
|
11
|
|
|
public const SCHEMA_ITEMTYPE = 'itemtype'; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* The tag used as container for fields in viewable() |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $viewableContainerTag = 'div'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The tag used as container for the entire html. |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $viewableBaseTag = 'div'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The tag used as container for fields in editable() |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $editableContainerTag = 'div'; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct(string $name = 'HTML') |
|
35
|
|
|
{ |
|
36
|
|
|
parent::__construct($name); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Get the tag used as container for the entire html. |
|
41
|
|
|
* |
|
42
|
|
|
* @return string |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getViewableBaseTag() |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->viewableBaseTag; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Set the tag used as container for the entire html. |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $viewableBaseTag The tag used as container for the entire html. |
|
53
|
|
|
* |
|
54
|
|
|
* @return self |
|
55
|
|
|
*/ |
|
56
|
|
|
public function setViewableBaseTag(string $viewableBaseTag): self |
|
57
|
|
|
{ |
|
58
|
|
|
$this->viewableBaseTag = $viewableBaseTag; |
|
59
|
|
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function getViewableContainerTag(): string |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->viewableContainerTag; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param string $tag |
|
69
|
|
|
* @return self |
|
70
|
|
|
*/ |
|
71
|
|
|
public function setViewableContainerTag(string $tag): self |
|
72
|
|
|
{ |
|
73
|
|
|
$this->viewableContainerTag = $tag; |
|
74
|
|
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getEditableContainerTag(): string |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->editableContainerTag; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param string $tag |
|
84
|
|
|
* @return self |
|
85
|
|
|
*/ |
|
86
|
|
|
public function setEditableContainerTag(string $tag): self |
|
87
|
|
|
{ |
|
88
|
|
|
$this->editableContainerTag = $tag; |
|
89
|
|
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Static counter to generate unique ids. |
|
94
|
|
|
* |
|
95
|
|
|
* @return integer |
|
96
|
|
|
*/ |
|
97
|
|
|
public static function counter(): int |
|
98
|
|
|
{ |
|
99
|
|
|
static $counter = 0; |
|
100
|
|
|
return $counter++; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function viewableCompose(\Formularium\Model $m, array $elements, string $previousCompose, FrameworkComposer $composer): string |
|
104
|
|
|
{ |
|
105
|
|
|
$atts = [ |
|
106
|
|
|
'class' => 'formularium-base' |
|
107
|
|
|
]; |
|
108
|
|
|
$schemaItemScope = $this->getOption('itemscope', $m->getRenderable('itemscope', false)); |
|
109
|
|
|
if ($schemaItemScope) { |
|
110
|
|
|
$atts['itemscope'] = ''; |
|
111
|
|
|
} |
|
112
|
|
|
$schemaItemType = $this->getOption('itemtype', $m->getRenderable('itemtype', null)); |
|
113
|
|
|
if ($schemaItemType) { |
|
114
|
|
|
$atts['itemtype'] = $schemaItemType; |
|
115
|
|
|
$atts['itemscope'] = ''; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
return HTMLNode::factory( |
|
119
|
|
|
$this->getViewableBaseTag(), |
|
120
|
|
|
$atts, |
|
121
|
|
|
join( |
|
122
|
|
|
'', |
|
123
|
|
|
array_map(function ($e) { |
|
124
|
|
|
return $e->__toString(); |
|
125
|
|
|
}, $elements) |
|
126
|
|
|
), |
|
127
|
|
|
true |
|
128
|
|
|
)->__toString(); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function editableCompose(\Formularium\Model $m, array $elements, string $previousCompose, FrameworkComposer $composer): string |
|
132
|
|
|
{ |
|
133
|
|
|
return join('', array_map(function ($e) { |
|
134
|
|
|
return $e->__toString(); |
|
135
|
|
|
}, $elements)); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|