2015-08-11 08:21:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specifies that this ends a group of fields
|
|
|
|
*/
|
|
|
|
class EditableFieldGroupEnd extends EditableFormField {
|
|
|
|
|
2015-08-12 07:18:43 +02:00
|
|
|
private static $belongs_to = array(
|
|
|
|
'Group' => 'EditableFieldGroup'
|
|
|
|
);
|
|
|
|
|
2015-08-11 08:21:43 +02:00
|
|
|
/**
|
|
|
|
* Disable selection of group class
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private static $hidden = true;
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2015-08-13 01:31:37 +02:00
|
|
|
/**
|
|
|
|
* Non-data type
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private static $literal = true;
|
2015-08-12 06:08:32 +02:00
|
|
|
|
2015-08-12 07:18:43 +02:00
|
|
|
public function getCMSTitle() {
|
|
|
|
$group = $this->Group();
|
|
|
|
return _t(
|
|
|
|
'EditableFieldGroupEnd.FIELD_GROUP_END',
|
2015-08-14 04:51:42 +02:00
|
|
|
'{group} end',
|
2015-08-12 07:18:43 +02:00
|
|
|
array(
|
2015-08-14 04:51:42 +02:00
|
|
|
'group' => ($group && $group->exists()) ? $group->CMSTitle : 'Group'
|
2015-08-12 07:18:43 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-08-12 06:08:32 +02:00
|
|
|
public function getCMSFields() {
|
|
|
|
$fields = parent::getCMSFields();
|
|
|
|
$fields->removeByName(array('MergeField', 'Default', 'Validation', 'DisplayRules'));
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getInlineClassnameField($column, $fieldClasses) {
|
2015-08-12 07:18:43 +02:00
|
|
|
return new LabelField($column, $this->CMSTitle);
|
2015-08-12 06:08:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getInlineTitleField($column) {
|
|
|
|
return HiddenField::create($column);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFormField() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function showInReports() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-12 07:18:43 +02:00
|
|
|
public function onAfterWrite() {
|
|
|
|
parent::onAfterWrite();
|
|
|
|
|
|
|
|
// If this is not attached to a group, find the first group prior to this
|
|
|
|
// with no end attached
|
|
|
|
$group = $this->Group();
|
|
|
|
if(!($group && $group->exists()) && $this->ParentID) {
|
|
|
|
$group = EditableFieldGroup::get()
|
|
|
|
->filter(array(
|
|
|
|
'ParentID' => $this->ParentID,
|
|
|
|
'Sort:LessThanOrEqual' => $this->Sort
|
|
|
|
))
|
|
|
|
->where('"EditableFieldGroup"."EndID" IS NULL OR "EditableFieldGroup"."EndID" = 0')
|
|
|
|
->sort('"Sort" DESC')
|
|
|
|
->first();
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2015-08-12 07:18:43 +02:00
|
|
|
// When a group is found, attach it to this end
|
|
|
|
if($group) {
|
|
|
|
$group->EndID = $this->ID;
|
|
|
|
$group->write();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function onAfterDelete() {
|
|
|
|
parent::onAfterDelete();
|
|
|
|
|
|
|
|
// Delete group
|
|
|
|
if(($group = $this->Group()) && $group->exists()) {
|
|
|
|
$group->delete();
|
|
|
|
}
|
2015-08-12 06:08:32 +02:00
|
|
|
}
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2015-08-11 08:21:43 +02:00
|
|
|
}
|