2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
2017-08-09 01:55:09 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\UserForms\Model\EditableFormField;
|
|
|
|
|
|
|
|
use SilverStripe\Forms\CheckboxField;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\Forms\DropdownField;
|
2021-02-26 04:13:23 +01:00
|
|
|
use SilverStripe\Forms\FieldList;
|
2017-08-09 01:55:09 +02:00
|
|
|
use SilverStripe\Forms\HeaderField;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\UserForms\Model\EditableFormField;
|
2017-08-09 01:55:09 +02:00
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
/**
|
|
|
|
* Allows an editor to insert a generic heading into a field
|
2009-04-17 04:26:40 +02:00
|
|
|
*
|
2012-04-14 08:36:50 +02:00
|
|
|
* @package userforms
|
2021-02-26 04:13:23 +01:00
|
|
|
* @property int $Level
|
|
|
|
* @property int $HideFromReports
|
2008-09-29 05:18:23 +02:00
|
|
|
*/
|
2016-07-21 07:53:59 +02:00
|
|
|
class EditableFormHeading extends EditableFormField
|
|
|
|
{
|
|
|
|
private static $singular_name = 'Heading';
|
|
|
|
|
|
|
|
private static $plural_name = 'Headings';
|
|
|
|
|
|
|
|
private static $literal = true;
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
private static $db = [
|
2016-07-21 07:53:59 +02:00
|
|
|
'Level' => 'Int(3)', // From CustomSettings
|
|
|
|
'HideFromReports' => 'Boolean(0)' // from CustomSettings
|
2017-08-11 01:33:06 +02:00
|
|
|
];
|
2016-07-21 07:53:59 +02:00
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
private static $defaults = [
|
2016-07-21 07:53:59 +02:00
|
|
|
'Level' => 3,
|
|
|
|
'HideFromReports' => false
|
2017-08-11 01:33:06 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
private static $table_name = 'EditableFormHeading';
|
2016-07-21 07:53:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getCMSFields()
|
|
|
|
{
|
|
|
|
$fields = parent::getCMSFields();
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
$fields->removeByName(['Default', 'Validation', 'RightTitle']);
|
2016-07-21 07:53:59 +02:00
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
$levels = [
|
2016-07-21 07:53:59 +02:00
|
|
|
'1' => '1',
|
|
|
|
'2' => '2',
|
|
|
|
'3' => '3',
|
|
|
|
'4' => '4',
|
|
|
|
'5' => '5',
|
|
|
|
'6' => '6'
|
2017-08-11 01:33:06 +02:00
|
|
|
];
|
2016-07-21 07:53:59 +02:00
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
$fields->addFieldsToTab('Root.Main', [
|
2016-07-21 07:53:59 +02:00
|
|
|
DropdownField::create(
|
|
|
|
'Level',
|
2017-08-11 01:33:06 +02:00
|
|
|
_t(__CLASS__.'.LEVEL', 'Select Heading Level'),
|
2016-07-21 07:53:59 +02:00
|
|
|
$levels
|
|
|
|
),
|
|
|
|
CheckboxField::create(
|
|
|
|
'HideFromReports',
|
2017-08-11 01:33:06 +02:00
|
|
|
_t('SilverStripe\\UserForms\\Model\\EditableFormField\\EditableLiteralField.HIDEFROMREPORT', 'Hide from reports?')
|
2016-07-21 07:53:59 +02:00
|
|
|
)
|
2017-08-11 01:33:06 +02:00
|
|
|
]);
|
2016-07-21 07:53:59 +02:00
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFormField()
|
|
|
|
{
|
2018-03-23 04:23:51 +01:00
|
|
|
$labelField = HeaderField::create('userforms-header', $this->Title ?: false)
|
2016-09-21 02:26:47 +02:00
|
|
|
->setHeadingLevel($this->Level);
|
2016-07-21 07:53:59 +02:00
|
|
|
$labelField->addExtraClass('FormHeading');
|
|
|
|
$labelField->setAttribute('data-id', $this->Name);
|
|
|
|
$this->doUpdateFormField($labelField);
|
|
|
|
return $labelField;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function updateFormField($field)
|
|
|
|
{
|
|
|
|
// set the right title on this field
|
|
|
|
if ($this->RightTitle) {
|
2018-03-21 02:56:16 +01:00
|
|
|
$field->setRightTitle($this->RightTitle);
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
2018-02-05 00:08:24 +01:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
// if this field has an extra class
|
|
|
|
if ($this->ExtraClass) {
|
|
|
|
$field->addExtraClass($this->ExtraClass);
|
|
|
|
}
|
2018-02-05 00:08:24 +01:00
|
|
|
|
|
|
|
if (!$this->ShowOnLoad) {
|
|
|
|
$field->addExtraClass($this->ShowOnLoadNice());
|
|
|
|
}
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function showInReports()
|
|
|
|
{
|
|
|
|
return !$this->HideFromReports;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldValidationOptions()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSelectorHolder()
|
|
|
|
{
|
|
|
|
return "$(\":header[data-id='{$this->Name}']\")";
|
|
|
|
}
|
|
|
|
|
2018-02-05 00:08:24 +01:00
|
|
|
public function getSelectorOnly()
|
|
|
|
{
|
|
|
|
return "[data-id={$this->Name}]";
|
|
|
|
}
|
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
public function getLevel()
|
|
|
|
{
|
|
|
|
return $this->getField('Level') ?: 3;
|
|
|
|
}
|
2012-09-10 06:07:52 +02:00
|
|
|
}
|