2015-08-11 08:21:43 +02:00
|
|
|
<?php
|
|
|
|
|
2017-08-09 01:55:09 +02:00
|
|
|
namespace SilverStripe\UserForms\Model\EditableFormField;
|
|
|
|
|
2022-03-03 04:47:45 +01:00
|
|
|
use SilverStripe\Forms\FieldList;
|
2017-08-09 01:55:09 +02:00
|
|
|
use SilverStripe\Forms\HiddenField;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\Forms\LabelField;
|
|
|
|
use SilverStripe\UserForms\Model\EditableFormField;
|
2017-08-09 01:55:09 +02:00
|
|
|
|
2015-08-11 08:21:43 +02:00
|
|
|
/**
|
|
|
|
* Specifies that this ends a group of fields
|
2021-02-26 04:13:23 +01:00
|
|
|
*
|
|
|
|
* @method EditableFieldGroup Group()
|
2015-08-11 08:21:43 +02:00
|
|
|
*/
|
2016-07-21 07:53:59 +02:00
|
|
|
class EditableFieldGroupEnd extends EditableFormField
|
|
|
|
{
|
2017-08-11 01:33:06 +02:00
|
|
|
private static $belongs_to = [
|
2017-08-09 01:55:09 +02:00
|
|
|
'Group' => EditableFieldGroup::class
|
2017-08-11 01:33:06 +02:00
|
|
|
];
|
2016-07-21 07:53:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable selection of group class
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private static $hidden = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Non-data type
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private static $literal = true;
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
private static $table_name = 'EditableFieldGroupEnd';
|
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
public function getCMSTitle()
|
|
|
|
{
|
|
|
|
$group = $this->Group();
|
|
|
|
return _t(
|
2017-08-11 01:33:06 +02:00
|
|
|
__CLASS__.'.FIELD_GROUP_END',
|
2016-07-21 07:53:59 +02:00
|
|
|
'{group} end',
|
2017-08-11 01:33:06 +02:00
|
|
|
[
|
2022-10-27 11:42:43 +02:00
|
|
|
'group' => ($group && $group->exists()) ? $group->CMSTitle : 'Group'
|
2017-08-11 01:33:06 +02:00
|
|
|
]
|
2016-07-21 07:53:59 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCMSFields()
|
|
|
|
{
|
2022-03-03 04:47:45 +01:00
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) {
|
|
|
|
$fields->removeByName(['MergeField', 'Default', 'Validation', 'DisplayRules']);
|
|
|
|
});
|
|
|
|
|
|
|
|
return parent::getCMSFields();
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getInlineClassnameField($column, $fieldClasses)
|
|
|
|
{
|
2017-08-11 01:33:06 +02:00
|
|
|
return LabelField::create($column, $this->CMSTitle);
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getInlineTitleField($column)
|
|
|
|
{
|
|
|
|
return HiddenField::create($column);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFormField()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function showInReports()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-05-20 07:06:29 +02:00
|
|
|
protected function onAfterWrite()
|
2016-07-21 07:53:59 +02:00
|
|
|
{
|
|
|
|
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()
|
2017-08-11 01:33:06 +02:00
|
|
|
->filter([
|
2016-07-21 07:53:59 +02:00
|
|
|
'ParentID' => $this->ParentID,
|
|
|
|
'Sort:LessThanOrEqual' => $this->Sort
|
2017-08-11 01:33:06 +02:00
|
|
|
])
|
2016-07-21 07:53:59 +02:00
|
|
|
->where('"EditableFieldGroup"."EndID" IS NULL OR "EditableFieldGroup"."EndID" = 0')
|
|
|
|
->sort('"Sort" DESC')
|
|
|
|
->first();
|
|
|
|
|
|
|
|
// When a group is found, attach it to this end
|
|
|
|
if ($group) {
|
|
|
|
$group->EndID = $this->ID;
|
|
|
|
$group->write();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-11 08:21:43 +02:00
|
|
|
}
|