/
DatalessField.php
94 lines (82 loc) · 1.8 KB
/
DatalessField.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace SilverStripe\Forms;
use SilverStripe\ORM\FieldType\DBHTMLText;
/**
* Abstract class for all fields without data.
* Labels, headings and the like should extend from this.
*/
class DatalessField extends FormField
{
/**
* @var bool $allowHTML
*/
protected $allowHTML;
/**
* function that returns whether this field contains data.
* Always returns false.
*/
public function hasData()
{
return false;
}
public function getAttributes()
{
return array_merge(
parent::getAttributes(),
[
'type' => 'hidden',
]
);
}
/**
* Returns the field's representation in the form.
* For dataless fields, this defaults to $Field.
*
* @param array $properties
* @return DBHTMLText
*/
public function FieldHolder($properties = [])
{
return $this->Field($properties);
}
/**
* Returns the field's representation in a field group.
* For dataless fields, this defaults to $Field.
*
* @param array $properties
* @return DBHTMLText
*/
public function SmallFieldHolder($properties = [])
{
return $this->Field($properties);
}
/**
* Returns a readonly version of this field
*/
public function performReadonlyTransformation()
{
$clone = clone $this;
$clone->setReadonly(true);
return $clone;
}
/**
* @param bool $bool
* @return $this
*/
public function setAllowHTML($bool)
{
$this->allowHTML = $bool;
return $this;
}
/**
* @return bool
*/
public function getAllowHTML()
{
return $this->allowHTML;
}
public function Type()
{
return 'readonly';
}
}