2015-08-11 08:21:43 +02:00
|
|
|
<?php
|
|
|
|
|
2017-08-09 01:55:09 +02:00
|
|
|
namespace SilverStripe\UserForms\Model\EditableFormField;
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\Core\Convert;
|
2017-08-09 01:55:09 +02:00
|
|
|
use SilverStripe\Forms\LabelField;
|
|
|
|
use SilverStripe\UserForms\FormField\UserFormsGroupField;
|
2017-08-11 02:36:28 +02:00
|
|
|
use SilverStripe\UserForms\Model\EditableFormField;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\UserForms\Model\EditableFormField\EditableFieldGroupEnd;
|
2017-08-09 01:55:09 +02:00
|
|
|
|
2015-08-11 08:21:43 +02:00
|
|
|
/**
|
|
|
|
* Specifies that this ends a group of fields
|
|
|
|
*/
|
2016-07-21 07:53:59 +02:00
|
|
|
class EditableFieldGroup extends EditableFormField
|
|
|
|
{
|
2017-08-11 01:33:06 +02:00
|
|
|
private static $has_one = [
|
2017-08-09 01:55:09 +02:00
|
|
|
'End' => EditableFieldGroupEnd::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 field type
|
|
|
|
*
|
|
|
|
* @var type
|
|
|
|
*/
|
|
|
|
private static $literal = true;
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
private static $table_name = 'EditableFieldGroup';
|
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
public function getCMSFields()
|
|
|
|
{
|
|
|
|
$fields = parent::getCMSFields();
|
2017-08-11 01:33:06 +02:00
|
|
|
$fields->removeByName(['MergeField', 'Default', 'Validation', 'DisplayRules']);
|
2016-07-21 07:53:59 +02:00
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCMSTitle()
|
|
|
|
{
|
|
|
|
$title = $this->getFieldNumber()
|
|
|
|
?: $this->Title
|
|
|
|
?: 'group';
|
|
|
|
|
|
|
|
return _t(
|
2017-08-11 01:33:06 +02:00
|
|
|
'SilverStripe\\UserForms\\Model\\EditableFormField\\EditableFieldGroupEnd.FIELD_GROUP_START',
|
2016-07-21 07:53:59 +02:00
|
|
|
'Group {group}',
|
2017-08-11 01:33:06 +02:00
|
|
|
['group' => $title]
|
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 showInReports()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFormField()
|
|
|
|
{
|
|
|
|
$field = UserFormsGroupField::create()
|
|
|
|
->setTitle($this->EscapedTitle ?: false)
|
|
|
|
->setName($this->Name);
|
|
|
|
$this->doUpdateFormField($field);
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function updateFormField($field)
|
|
|
|
{
|
|
|
|
// set the right title on this field
|
|
|
|
if ($this->RightTitle) {
|
|
|
|
// Since this field expects raw html, safely escape the user data prior
|
|
|
|
$field->setRightTitle(Convert::raw2xml($this->RightTitle));
|
|
|
|
}
|
|
|
|
|
|
|
|
// if this field has an extra class
|
|
|
|
if ($this->ExtraClass) {
|
|
|
|
$field->addExtraClass($this->ExtraClass);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function onBeforeDelete()
|
|
|
|
{
|
|
|
|
parent::onBeforeDelete();
|
|
|
|
|
|
|
|
// Ensures EndID is lazy-loaded for onAfterDelete
|
|
|
|
$this->EndID;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function onAfterDelete()
|
|
|
|
{
|
|
|
|
parent::onAfterDelete();
|
|
|
|
|
|
|
|
// Delete end
|
|
|
|
if (($end = $this->End()) && $end->exists()) {
|
|
|
|
$end->delete();
|
|
|
|
}
|
|
|
|
}
|
2015-08-11 08:21:43 +02:00
|
|
|
}
|