1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Specifies that this ends a group of fields |
5
|
|
|
*/ |
6
|
|
|
class EditableFieldGroupEnd extends EditableFormField |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
private static $belongs_to = array( |
|
|
|
|
10
|
|
|
'Group' => 'EditableFieldGroup' |
11
|
|
|
); |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Disable selection of group class |
15
|
|
|
* |
16
|
|
|
* @config |
17
|
|
|
* @var bool |
18
|
|
|
*/ |
19
|
|
|
private static $hidden = true; |
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Non-data type |
23
|
|
|
* |
24
|
|
|
* @config |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
private static $literal = true; |
|
|
|
|
28
|
|
|
|
29
|
|
|
public function getCMSTitle() |
30
|
|
|
{ |
31
|
|
|
$group = $this->Group(); |
|
|
|
|
32
|
|
|
return _t( |
33
|
|
|
'EditableFieldGroupEnd.FIELD_GROUP_END', |
34
|
|
|
'{group} end', |
35
|
|
|
array( |
|
|
|
|
36
|
|
|
'group' => ($group && $group->exists()) ? $group->CMSTitle : 'Group' |
37
|
|
|
) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getCMSFields() |
42
|
|
|
{ |
43
|
|
|
$fields = parent::getCMSFields(); |
44
|
|
|
$fields->removeByName(array('MergeField', 'Default', 'Validation', 'DisplayRules')); |
45
|
|
|
return $fields; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getInlineClassnameField($column, $fieldClasses) |
49
|
|
|
{ |
50
|
|
|
return new LabelField($column, $this->CMSTitle); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getInlineTitleField($column) |
54
|
|
|
{ |
55
|
|
|
return HiddenField::create($column); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getFormField() |
59
|
|
|
{ |
60
|
|
|
return null; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function showInReports() |
64
|
|
|
{ |
65
|
|
|
return false; |
66
|
|
|
} |
67
|
|
|
|
68
|
26 |
|
public function onAfterWrite() |
69
|
|
|
{ |
70
|
26 |
|
parent::onAfterWrite(); |
71
|
|
|
|
72
|
|
|
// If this is not attached to a group, find the first group prior to this |
73
|
|
|
// with no end attached |
74
|
26 |
|
$group = $this->Group(); |
|
|
|
|
75
|
26 |
|
if (!($group && $group->exists()) && $this->ParentID) { |
|
|
|
|
76
|
1 |
|
$group = EditableFieldGroup::get() |
77
|
1 |
|
->filter(array( |
78
|
1 |
|
'ParentID' => $this->ParentID, |
|
|
|
|
79
|
1 |
|
'Sort:LessThanOrEqual' => $this->Sort |
80
|
1 |
|
)) |
81
|
1 |
|
->where('"EditableFieldGroup"."EndID" IS NULL OR "EditableFieldGroup"."EndID" = 0') |
82
|
1 |
|
->sort('"Sort" DESC') |
83
|
1 |
|
->first(); |
84
|
|
|
|
85
|
|
|
// When a group is found, attach it to this end |
86
|
1 |
|
if ($group) { |
87
|
|
|
$group->EndID = $this->ID; |
88
|
|
|
$group->write(); |
89
|
|
|
} |
90
|
1 |
|
} |
91
|
26 |
|
} |
92
|
|
|
|
93
|
|
|
protected function onAfterDelete() |
94
|
|
|
{ |
95
|
|
|
parent::onAfterDelete(); |
96
|
|
|
|
97
|
|
|
// Delete group |
98
|
|
|
if (($group = $this->Group()) && $group->exists()) { |
|
|
|
|
99
|
|
|
$group->delete(); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
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.