|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\UserForms\Model\EditableFormField; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Core\Convert; |
|
6
|
|
|
use SilverStripe\Forms\CheckboxField; |
|
7
|
|
|
use SilverStripe\Forms\DropdownField; |
|
8
|
|
|
use SilverStripe\Forms\HeaderField; |
|
9
|
|
|
use SilverStripe\UserForms\Model\EditableFormField; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Allows an editor to insert a generic heading into a field |
|
13
|
|
|
* |
|
14
|
|
|
* @package userforms |
|
15
|
|
|
*/ |
|
16
|
|
|
class EditableFormHeading extends EditableFormField |
|
17
|
|
|
{ |
|
18
|
|
|
private static $singular_name = 'Heading'; |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
private static $plural_name = 'Headings'; |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
private static $literal = true; |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
private static $db = [ |
|
|
|
|
|
|
25
|
|
|
'Level' => 'Int(3)', // From CustomSettings |
|
26
|
|
|
'HideFromReports' => 'Boolean(0)' // from CustomSettings |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
private static $defaults = [ |
|
|
|
|
|
|
30
|
|
|
'Level' => 3, |
|
31
|
|
|
'HideFromReports' => false |
|
32
|
|
|
]; |
|
33
|
|
|
|
|
34
|
|
|
private static $table_name = 'EditableFormHeading'; |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return FieldList |
|
|
|
|
|
|
38
|
|
|
*/ |
|
39
|
|
|
public function getCMSFields() |
|
40
|
|
|
{ |
|
41
|
|
|
$fields = parent::getCMSFields(); |
|
42
|
|
|
|
|
43
|
|
|
$fields->removeByName(['Default', 'Validation', 'RightTitle']); |
|
44
|
|
|
|
|
45
|
|
|
$levels = [ |
|
46
|
|
|
'1' => '1', |
|
47
|
|
|
'2' => '2', |
|
48
|
|
|
'3' => '3', |
|
49
|
|
|
'4' => '4', |
|
50
|
|
|
'5' => '5', |
|
51
|
|
|
'6' => '6' |
|
52
|
|
|
]; |
|
53
|
|
|
|
|
54
|
|
|
$fields->addFieldsToTab('Root.Main', [ |
|
55
|
|
|
DropdownField::create( |
|
56
|
|
|
'Level', |
|
57
|
|
|
_t(__CLASS__.'.LEVEL', 'Select Heading Level'), |
|
58
|
|
|
$levels |
|
59
|
|
|
), |
|
60
|
|
|
CheckboxField::create( |
|
61
|
|
|
'HideFromReports', |
|
62
|
|
|
_t('SilverStripe\\UserForms\\Model\\EditableFormField\\EditableLiteralField.HIDEFROMREPORT', 'Hide from reports?') |
|
63
|
|
|
) |
|
64
|
|
|
]); |
|
65
|
|
|
|
|
66
|
|
|
return $fields; |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getFormField() |
|
70
|
|
|
{ |
|
71
|
|
|
$labelField = HeaderField::create('userforms-header', $this->Title ?: false) |
|
72
|
|
|
->setHeadingLevel($this->Level); |
|
|
|
|
|
|
73
|
|
|
$labelField->addExtraClass('FormHeading'); |
|
74
|
|
|
$labelField->setAttribute('data-id', $this->Name); |
|
75
|
|
|
$this->doUpdateFormField($labelField); |
|
76
|
|
|
return $labelField; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
protected function updateFormField($field) |
|
80
|
|
|
{ |
|
81
|
|
|
// set the right title on this field |
|
82
|
|
|
if ($this->RightTitle) { |
|
|
|
|
|
|
83
|
|
|
$field->setRightTitle($this->RightTitle); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
// if this field has an extra class |
|
87
|
|
|
if ($this->ExtraClass) { |
|
|
|
|
|
|
88
|
|
|
$field->addExtraClass($this->ExtraClass); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if (!$this->ShowOnLoad) { |
|
92
|
|
|
$field->addExtraClass($this->ShowOnLoadNice()); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function showInReports() |
|
97
|
|
|
{ |
|
98
|
|
|
return !$this->HideFromReports; |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function getFieldValidationOptions() |
|
102
|
|
|
{ |
|
103
|
|
|
return false; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function getSelectorHolder() |
|
107
|
|
|
{ |
|
108
|
|
|
return "$(\":header[data-id='{$this->Name}']\")"; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function getSelectorOnly() |
|
112
|
|
|
{ |
|
113
|
|
|
return "[data-id={$this->Name}]"; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function getLevel() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->getField('Level') ?: 3; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|