silverstripe-userforms/code/Model/EditableFormField/EditableFormStep.php

101 lines
2.2 KiB
PHP
Raw Normal View History

2015-08-04 07:12:17 +02:00
<?php
namespace SilverStripe\UserForms\Model\EditableFormField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormField;
use SilverStripe\Forms\LabelField;
use SilverStripe\UserForms\FormField\UserFormsStepField;
use SilverStripe\UserForms\Model\EditableFormField;
2015-08-04 07:12:17 +02:00
/**
* A step in multi-page user form
*
* @package userforms
*/
2016-07-21 07:53:59 +02:00
class EditableFormStep extends EditableFormField
{
private static $singular_name = 'Page Break';
2016-07-21 07:53:59 +02:00
private static $plural_name = 'Page Breaks';
2016-07-21 07:53:59 +02:00
/**
* Disable selection of step class
*
* @config
* @var bool
*/
private static $hidden = true;
2015-08-11 08:21:43 +02:00
private static $table_name = 'EditableFormStep';
2016-07-21 07:53:59 +02:00
/**
* @return FieldList
*/
public function getCMSFields()
{
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->removeByName(['MergeField', 'Default', 'Validation', 'RightTitle']);
});
2015-08-04 07:12:17 +02:00
return parent::getCMSFields();
2016-07-21 07:53:59 +02:00
}
2015-08-04 07:12:17 +02:00
2016-07-21 07:53:59 +02:00
/**
* @return FormField
*/
public function getFormField()
{
$field = UserFormsStepField::create()
->setName($this->Name)
->setTitle($this->Title);
2016-07-21 07:53:59 +02:00
$this->doUpdateFormField($field);
2016-07-21 07:53:59 +02:00
return $field;
}
2016-07-21 07:53:59 +02:00
protected function updateFormField($field)
{
// if this field has an extra class
if ($this->ExtraClass) {
$field->addExtraClass($this->ExtraClass);
}
}
2015-08-04 07:12:17 +02:00
2016-07-21 07:53:59 +02:00
/**
* @return boolean
*/
public function showInReports()
{
return false;
}
2016-07-21 07:53:59 +02:00
public function getInlineClassnameField($column, $fieldClasses)
{
return LabelField::create($column, $this->CMSTitle);
2016-07-21 07:53:59 +02:00
}
2016-07-21 07:53:59 +02:00
public function getCMSTitle()
{
$title = $this->getFieldNumber()
?: $this->Title
?: '';
2015-08-14 04:51:42 +02:00
2016-07-21 07:53:59 +02:00
return _t(
__CLASS__.'.STEP_TITLE',
2016-07-21 07:53:59 +02:00
'Page {page}',
['page' => $title]
2016-07-21 07:53:59 +02:00
);
}
2015-08-17 00:43:51 +02:00
2016-07-21 07:53:59 +02: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 07:12:17 +02:00
}