|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
*@author nicolaas[at]sunnysideup.co.nz |
|
5
|
|
|
*@description contains a list of form fields and their explantions, is added to SiteTree |
|
6
|
|
|
* |
|
7
|
|
|
**/ |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class FormFieldExplanationDecorator extends DataObjectDecorator |
|
|
|
|
|
|
11
|
|
|
{ |
|
12
|
|
|
protected static $show_fields_in_cms = false; |
|
13
|
|
|
public static function set_show_fields_in_cms($v) |
|
14
|
|
|
{ |
|
15
|
|
|
self::$show_fields_in_cms = $v; |
|
16
|
|
|
} |
|
17
|
|
|
public static function get_show_fields_in_cms() |
|
18
|
|
|
{ |
|
19
|
|
|
return self::$show_fields_in_cms; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function extraStatics() |
|
23
|
|
|
{ |
|
24
|
|
|
return array( |
|
25
|
|
|
'has_many' => array( |
|
26
|
|
|
'FormFieldExplanation' => 'FormFieldExplanation' |
|
27
|
|
|
) |
|
28
|
|
|
); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function updateCMSFields(FieldSet &$fields) |
|
32
|
|
|
{ |
|
33
|
|
|
$bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; |
|
34
|
|
|
if (DataObject::get_one("FormFieldExplanation", "{$bt}ParentID{$bt} = ".$this->owner->ID)) { |
|
35
|
|
|
$fields->addFieldToTab("Root.Content.FormExplanations", $this->getFormFieldExplanationHasManyTable()); |
|
36
|
|
|
} |
|
37
|
|
|
return $fields; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
public function getFormFieldExplanationHasManyTable() |
|
42
|
|
|
{ |
|
43
|
|
|
$bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; |
|
44
|
|
|
$field = new HasManyComplexTableField( |
|
45
|
|
|
$controller = $this->owner, |
|
46
|
|
|
$name = "FormFieldExplanation", |
|
47
|
|
|
$sourceClass = "FormFieldExplanation", |
|
48
|
|
|
$fieldList = array("Title" => "Title"), |
|
49
|
|
|
$detailFormFields = null, |
|
50
|
|
|
$sourceFilter = "{$bt}ParentID{$bt} =".$this->owner->ID, |
|
51
|
|
|
$sourceSort = "", |
|
52
|
|
|
$sourceJoin = "" |
|
53
|
|
|
); |
|
54
|
|
|
$field->setPermissions(array("edit", "delete")); |
|
55
|
|
|
$field->setParentClass($this->owner->class); |
|
56
|
|
|
$field->relationAutoSetting = true; |
|
57
|
|
|
return $field; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
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.