silverstripe-userforms/code/model/editableformfields/EditableFormHeading.php
Damian Mooyman 9f112e3b23 Add "Add page break" button
Fix unit test failures
2015-08-11 14:18:46 +12:00

84 lines
1.8 KiB
PHP
Executable File

<?php
/**
* Allows an editor to insert a generic heading into a field
*
* @package userforms
*/
class EditableFormHeading extends EditableFormField {
private static $singular_name = 'Heading';
private static $plural_name = 'Headings';
private static $db = array(
'Level' => 'Int(3)', // From CustomSettings
'HideFromReports' => 'Boolean(0)' // from CustomSettings
);
private static $defaults = array(
'Level' => 3,
'HideFromReports' => false
);
/**
* @return FieldList
*/
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeByName('Default');
$fields->removeByName('Validation');
$levels = array(
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6'
);
$fields->addFieldsToTab('Root.Main', array(
DropdownField::create(
'Level',
_t('EditableFormHeading.LEVEL', 'Select Heading Level'),
$levels
),
CheckboxField::create(
'HideFromReports',
_t('EditableLiteralField.HIDEFROMREPORT', 'Hide from reports?')
)
));
return $fields;
}
public function getFormField() {
$labelField = new HeaderField($this->Name, $this->EscapedTitle, $this->Level);
$labelField->addExtraClass('FormHeading');
$this->doUpdateFormField($labelField);
return $labelField;
}
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($field->ExtraClass) {
$field->addExtraClass($field->ExtraClass);
}
}
public function showInReports() {
return !$this->HideFromReports;
}
public function getFieldValidationOptions() {
return false;
}
}