2015-08-04 17:12:17 +12:00
|
|
|
<?php
|
2017-08-09 11:55:09 +12:00
|
|
|
|
|
|
|
namespace SilverStripe\UserForms\Model\EditableFormField;
|
|
|
|
|
2021-02-26 16:13:23 +13:00
|
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
use SilverStripe\Forms\FormField;
|
2017-08-09 11:55:09 +12:00
|
|
|
use SilverStripe\Forms\LabelField;
|
2017-08-11 11:33:06 +12:00
|
|
|
use SilverStripe\UserForms\FormField\UserFormsStepField;
|
|
|
|
use SilverStripe\UserForms\Model\EditableFormField;
|
2017-08-09 11:55:09 +12:00
|
|
|
|
2015-08-04 17:12:17 +12:00
|
|
|
/**
|
|
|
|
* A step in multi-page user form
|
|
|
|
*
|
|
|
|
* @package userforms
|
|
|
|
*/
|
2016-07-21 17:53:59 +12:00
|
|
|
class EditableFormStep extends EditableFormField
|
|
|
|
{
|
|
|
|
private static $singular_name = 'Page Break';
|
2015-08-12 17:18:43 +12:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
private static $plural_name = 'Page Breaks';
|
2015-08-12 17:18:43 +12:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
/**
|
|
|
|
* Disable selection of step class
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private static $hidden = true;
|
2015-08-11 18:21:43 +12:00
|
|
|
|
2017-08-11 11:33:06 +12:00
|
|
|
private static $table_name = 'EditableFormStep';
|
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getCMSFields()
|
|
|
|
{
|
2022-03-03 16:47:45 +13:00
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) {
|
|
|
|
$fields->removeByName(['MergeField', 'Default', 'Validation', 'RightTitle']);
|
|
|
|
});
|
2015-08-04 17:12:17 +12:00
|
|
|
|
2022-03-03 16:47:45 +13:00
|
|
|
return parent::getCMSFields();
|
2016-07-21 17:53:59 +12:00
|
|
|
}
|
2015-08-04 17:12:17 +12:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
/**
|
|
|
|
* @return FormField
|
|
|
|
*/
|
|
|
|
public function getFormField()
|
|
|
|
{
|
|
|
|
$field = UserFormsStepField::create()
|
|
|
|
->setName($this->Name)
|
2018-03-21 14:56:16 +13:00
|
|
|
->setTitle($this->Title);
|
2016-07-21 17:53:59 +12:00
|
|
|
$this->doUpdateFormField($field);
|
2021-02-26 16:13:23 +13:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
return $field;
|
|
|
|
}
|
2015-08-10 17:03:36 +12:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
protected function updateFormField($field)
|
|
|
|
{
|
|
|
|
// if this field has an extra class
|
|
|
|
if ($this->ExtraClass) {
|
|
|
|
$field->addExtraClass($this->ExtraClass);
|
|
|
|
}
|
|
|
|
}
|
2015-08-04 17:12:17 +12:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
/**
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function showInReports()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-12 16:08:32 +12:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
public function getInlineClassnameField($column, $fieldClasses)
|
|
|
|
{
|
2017-08-11 11:33:06 +12:00
|
|
|
return LabelField::create($column, $this->CMSTitle);
|
2016-07-21 17:53:59 +12:00
|
|
|
}
|
2015-08-12 17:18:43 +12:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
public function getCMSTitle()
|
|
|
|
{
|
|
|
|
$title = $this->getFieldNumber()
|
|
|
|
?: $this->Title
|
|
|
|
?: '';
|
2015-08-14 14:51:42 +12:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
return _t(
|
2017-08-11 11:39:58 +12:00
|
|
|
__CLASS__.'.STEP_TITLE',
|
2016-07-21 17:53:59 +12:00
|
|
|
'Page {page}',
|
2017-08-11 11:33:06 +12:00
|
|
|
['page' => $title]
|
2016-07-21 17:53:59 +12:00
|
|
|
);
|
|
|
|
}
|
2015-08-17 10:43:51 +12:00
|
|
|
|
2016-07-21 17:53:59 +12:00
|
|
|
/**
|
|
|
|
* Get the JS expression for selecting the holder for this field
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getSelectorHolder()
|
|
|
|
{
|
|
|
|
return "$(\".step-button-wrapper[data-for='{$this->Name}']\")";
|
|
|
|
}
|
2015-08-04 17:12:17 +12:00
|
|
|
}
|