1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* EditableCheckbox |
4
|
|
|
* A user modifiable checkbox on a UserDefinedForm |
5
|
|
|
* |
6
|
|
|
* @package userforms |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
class EditableTermsAndConditionsCheckbox extends EditableFormField |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
private static $singular_name = 'Terms and Conditions Checkbox'; |
|
|
|
|
12
|
|
|
|
13
|
|
|
private static $plural_name = 'Terms and Conditions Checkboxes'; |
|
|
|
|
14
|
|
|
|
15
|
|
|
private static $has_one = array( |
|
|
|
|
16
|
|
|
"TandCPage" => "SiteTree" |
17
|
|
|
); |
18
|
|
|
|
19
|
|
|
public function getFieldConfiguration() |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$options = parent::getFieldConfiguration(); |
22
|
|
|
$options->push(new CheckboxField("Fields[$this->ID][CustomSettings][Default]", _t('EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?'), $this->getSetting('Default'))); |
23
|
|
|
|
24
|
|
|
$defaultID = ($this->getSetting('TandCPageID')) ? $this->getSetting('TandCPageID') : 0; |
25
|
|
|
$pages = TermsAndConditionsPage::get(); |
26
|
|
|
if ($pages->count()) { |
27
|
|
|
$source = TermsAndConditionsPage::get()->map("ID", "Title")->toArray(); |
28
|
|
|
$options->push(new DropdownField("Fields[$this->ID][CustomSettings][TandCPageID]", "What is your Terms and Conditions page? This will be added as a link to the end of your field title.", $source, $defaultID)); |
29
|
|
|
} else { |
30
|
|
|
$options->push(new LiteralField("Fields[$this->ID][CustomSettings][TandCPageID]", "<p>You need to add a Terms and Conditions page before you can link to it (which is usually what you do here).</p>")); |
31
|
|
|
} |
32
|
|
|
return $options; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function getFormField() |
36
|
|
|
{ |
37
|
|
|
$id = intval($this->getSetting('TandCPageID')) - 0; |
38
|
|
|
$page = TermsAndConditionsPage::get()->byID($id); |
39
|
|
|
$extraHTML = ''; |
40
|
|
|
if ($page) { |
41
|
|
|
$extraHTML = ' <span class="linkToTermsAndConditionsPage"><a href="'.$page->Link().'" class="externalLink" target="_blank">'.$page->Title.'</a></span>'; |
42
|
|
|
} |
43
|
|
|
return new CheckboxField($this->Name, $this->Title.$extraHTML, $this->getSetting('Default')); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getValueFromData($data) |
47
|
|
|
{ |
48
|
|
|
$value = (isset($data[$this->Name])) ? $data[$this->Name] : false; |
49
|
|
|
return ($value) ? _t('EditableFormField.YES', 'Yes') : _t('EditableFormField.NO', 'No'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function Icon() |
53
|
|
|
{ |
54
|
|
|
return 'termsandconditions/images/' . strtolower($this->class) . '.png'; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function onBeforeWrite() |
58
|
|
|
{ |
59
|
|
|
parent::onBeforeWrite(); |
60
|
|
|
$this->Required = true; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.