|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace hemio\form\Abstract_; |
|
4
|
|
|
|
|
5
|
|
|
use hemio\form\exception; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
abstract class FormElement extends \hemio\form\Container { |
|
11
|
|
|
|
|
12
|
|
|
use \hemio\form\Trait_\MaintainsTransformations; |
|
13
|
|
|
|
|
14
|
|
|
protected $name = ''; |
|
15
|
|
|
protected $idSuffix = null; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Is active value in the form correct. |
|
19
|
|
|
* |
|
20
|
|
|
* @return boolean |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract public function dataValid(); |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Get the form to which this element belongs |
|
26
|
|
|
* |
|
27
|
|
|
* @return Abstract_\Form |
|
28
|
|
|
* @throws exception\NotLazyEnough |
|
29
|
|
|
*/ |
|
30
|
|
|
public function getForm() { |
|
31
|
|
|
if ($this->existsInheritableAppendage('_FORM')) |
|
32
|
|
|
return $this->getInheritableAppendage('_FORM'); |
|
33
|
|
|
else { |
|
34
|
|
|
throw new exception\NotLazyEnough( |
|
35
|
|
|
'No Form for FormElement found. Maybe not yet a child of a Form.' |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* |
|
42
|
|
|
* @return string |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getName() { |
|
45
|
|
|
return $this->name; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* |
|
50
|
|
|
* @param array $extraKeys |
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getHtmlName(array $extraKeys = []) { |
|
54
|
|
|
return sprintf('%s_%s%s' |
|
55
|
|
|
, $this->getForm()->getHtmlName() |
|
56
|
|
|
, $this->getName() |
|
57
|
|
|
, implode('_', $extraKeys) |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* |
|
63
|
|
|
* @param array $extraKeys |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getHtmlId(array $extraKeys = []) { |
|
67
|
|
|
return sprintf('%s_%s%s' |
|
68
|
|
|
, $this->getForm()->getHtmlName() |
|
69
|
|
|
, $this->getName() |
|
70
|
|
|
, $this->idSuffix === null ? '' : '_' . $this->idSuffix |
|
71
|
|
|
, implode('_', $extraKeys) |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getValueUser() { |
|
76
|
|
|
return $this->withTransformations( |
|
77
|
|
|
$this->getForm()->getValueUser($this->getHtmlName()) |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|