2008-10-03 00:05:45 +02:00
|
|
|
<?php
|
|
|
|
|
2017-05-18 07:11:01 +02:00
|
|
|
use SilverStripe\Core\Injector\Injector;
|
|
|
|
use SilverStripe\Forms\CheckboxSetField;
|
|
|
|
use SilverStripe\Forms\CurrencyField;
|
|
|
|
use SilverStripe\Forms\DateField;
|
|
|
|
use SilverStripe\Forms\DatetimeField;
|
|
|
|
use SilverStripe\Forms\EmailField;
|
|
|
|
use SilverStripe\Forms\GroupedDropdownField;
|
|
|
|
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
|
|
|
|
use SilverStripe\Forms\ListboxField;
|
|
|
|
use SilverStripe\Forms\MoneyField;
|
|
|
|
use SilverStripe\Forms\NumericField;
|
|
|
|
use SilverStripe\Forms\OptionsetField;
|
|
|
|
use SilverStripe\Forms\ReadonlyField;
|
|
|
|
use SilverStripe\Forms\SelectionGroup;
|
|
|
|
use SilverStripe\Forms\TextareaField;
|
|
|
|
use SilverStripe\Forms\TimeField;
|
|
|
|
use SilverStripe\Forms\ToggleCompositeField;
|
2016-07-01 04:37:50 +02:00
|
|
|
use SilverStripe\ORM\DataObject;
|
|
|
|
use SilverStripe\FrameworkTest\Model\TestCategory;
|
|
|
|
use SilverStripe\FrameworkTest\Model\TestPage;
|
|
|
|
use SilverStripe\FrameworkTest\Model\TestPage_Controller;
|
2016-09-07 07:10:55 +02:00
|
|
|
use SilverStripe\Forms\TextField;
|
|
|
|
use SilverStripe\Forms\SelectionGroup_Item;
|
|
|
|
use SilverStripe\Forms\FieldList;
|
2017-03-29 22:32:57 +02:00
|
|
|
use SilverStripe\AssetAdmin\Forms\UploadField;
|
2016-09-07 07:10:55 +02:00
|
|
|
use SilverStripe\Forms\LabelField;
|
|
|
|
use SilverStripe\Forms\LiteralField;
|
|
|
|
use SilverStripe\Forms\DropdownField;
|
|
|
|
use SilverStripe\Forms\CheckboxField;
|
|
|
|
use SilverStripe\Forms\FieldGroup;
|
|
|
|
use SilverStripe\Forms\CompositeField;
|
|
|
|
use SilverStripe\Forms\RequiredFields;
|
2016-10-20 11:06:02 +02:00
|
|
|
use SilverStripe\Forms\HTMLReadonlyField;
|
2016-07-01 04:37:50 +02:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
class BasicFieldsTestPage extends TestPage
|
|
|
|
{
|
2017-11-27 08:24:08 +01:00
|
|
|
private static $table_name = 'BasicFieldsTestPage';
|
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
private static $db = array(
|
|
|
|
'CalendarDate' => 'Date',
|
2016-10-18 05:32:13 +02:00
|
|
|
'Checkbox' => 'Boolean',
|
|
|
|
'ConfirmedPassword' => 'Varchar',
|
|
|
|
'CreditCard' => 'Varchar',
|
2015-12-17 21:20:49 +01:00
|
|
|
'Date' => 'Date',
|
|
|
|
'DateTime' => 'Datetime',
|
|
|
|
'DateTimeWithCalendar' => 'Datetime',
|
2016-10-18 05:32:13 +02:00
|
|
|
'DBFile' => 'DBFile',
|
2015-12-17 21:20:49 +01:00
|
|
|
'Email' => 'Varchar',
|
|
|
|
'HTMLField' => 'HTMLText',
|
2016-10-18 05:32:13 +02:00
|
|
|
'Money' => 'Money',
|
2016-10-18 05:38:41 +02:00
|
|
|
'MyCompositeField1' => 'Varchar',
|
|
|
|
'MyCompositeField2' => 'Varchar',
|
|
|
|
'MyCompositeField3' => 'Varchar',
|
|
|
|
'MyCompositeFieldCheckbox' => 'Boolean',
|
|
|
|
'MyFieldGroup1' => 'Varchar',
|
|
|
|
'MyFieldGroup2' => 'Varchar',
|
|
|
|
'MyFieldGroup3' => 'Varchar',
|
|
|
|
'MyFieldGroupCheckbox' => 'Boolean',
|
2016-10-18 06:17:35 +02:00
|
|
|
'MyLabelledFieldGroup1' => 'Varchar',
|
|
|
|
'MyLabelledFieldGroup2' => 'Varchar',
|
|
|
|
'MyLabelledFieldGroup3' => 'Int',
|
|
|
|
'MyLabelledFieldGroupCheckbox' => 'Boolean',
|
2017-02-15 20:23:09 +01:00
|
|
|
'Number' => 'Float',
|
2016-10-18 05:38:41 +02:00
|
|
|
'OptionSet' => 'Varchar',
|
2016-10-18 05:32:13 +02:00
|
|
|
'Password' => 'Varchar',
|
|
|
|
'PhoneNumber' => 'Varchar',
|
|
|
|
'Price' => 'Double',
|
|
|
|
'Readonly' => 'Varchar',
|
|
|
|
'Required' => 'Text',
|
|
|
|
'Text' => 'Varchar',
|
|
|
|
'Textarea' => 'Text',
|
|
|
|
'Time' => 'Time',
|
2017-03-31 03:12:56 +02:00
|
|
|
'TimeHTML5' => 'Time',
|
2016-10-18 06:17:35 +02:00
|
|
|
'ToggleCompositeTextField1' => 'Varchar',
|
|
|
|
'ToggleCompositeDropdownField' => 'Varchar',
|
2016-10-18 05:32:13 +02:00
|
|
|
'Validated' => 'Text',
|
2015-12-17 21:20:49 +01:00
|
|
|
);
|
2016-04-18 23:27:29 +02:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
private static $has_one = array(
|
2016-10-18 05:32:13 +02:00
|
|
|
'AttachedFile' => 'SilverStripe\\Assets\\File',
|
2016-07-01 04:37:50 +02:00
|
|
|
'Dropdown' => 'SilverStripe\\FrameworkTest\\Model\\TestCategory',
|
2016-09-07 07:10:55 +02:00
|
|
|
'File' => 'SilverStripe\\Assets\\File',
|
2016-10-18 05:32:13 +02:00
|
|
|
'GroupedDropdown' => 'SilverStripe\\FrameworkTest\\Model\\TestCategory',
|
2016-09-07 07:10:55 +02:00
|
|
|
'Image' => 'SilverStripe\\Assets\\Image',
|
2015-12-17 21:20:49 +01:00
|
|
|
);
|
2012-02-29 14:27:36 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
private static $has_many = array(
|
2016-09-07 07:10:55 +02:00
|
|
|
'HasManyFiles' => 'SilverStripe\\Assets\\File',
|
2015-12-17 21:20:49 +01:00
|
|
|
);
|
2012-02-29 14:27:36 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
private static $many_many = array(
|
2016-09-07 07:10:55 +02:00
|
|
|
'ManyManyFiles' => 'SilverStripe\\Assets\\File',
|
2016-10-18 12:15:37 +02:00
|
|
|
'CheckboxSet' => 'SilverStripe\\FrameworkTest\\Model\\TestCategory',
|
|
|
|
'Listbox' => 'SilverStripe\\FrameworkTest\\Model\\TestCategory',
|
2015-12-17 21:20:49 +01:00
|
|
|
);
|
2012-12-13 14:59:32 +01:00
|
|
|
|
2017-07-06 04:20:29 +02:00
|
|
|
private static $owns = [
|
|
|
|
'AttachedFile',
|
|
|
|
'File',
|
|
|
|
'Image',
|
|
|
|
];
|
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
private static $defaults = array(
|
|
|
|
'Validated' => 2
|
|
|
|
);
|
2013-09-18 13:01:56 +02:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
public function requireDefaultRecords()
|
|
|
|
{
|
|
|
|
parent::requireDefaultRecords();
|
2012-12-13 14:59:32 +01:00
|
|
|
|
2021-05-27 05:25:38 +02:00
|
|
|
if ($inst = DataObject::get_one('BasicFieldsTestPage') && static::config()->get('regenerate_on_build')) {
|
2015-12-17 21:20:49 +01:00
|
|
|
$data = $this->getDefaultData();
|
|
|
|
$inst->update($data);
|
|
|
|
$inst->write();
|
2016-10-18 06:17:35 +02:00
|
|
|
TestCategory::create()->requireDefaultRecords();
|
|
|
|
$cats = TestCategory::get();
|
|
|
|
$firstCat = $cats->offsetGet(0);
|
|
|
|
$thirdCat = $cats->offsetGet(2);
|
2016-10-18 12:15:37 +02:00
|
|
|
$inst->Listbox()->add($firstCat);
|
|
|
|
$inst->Listbox()->add($thirdCat);
|
|
|
|
$inst->CheckboxSet()->add($firstCat);
|
|
|
|
$inst->CheckboxSet()->add($thirdCat);
|
2016-10-18 06:17:35 +02:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
}
|
|
|
|
}
|
2012-12-13 14:59:32 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
public function getDefaultData()
|
|
|
|
{
|
|
|
|
$cats = TestCategory::get();
|
|
|
|
if (!$cats->Count()) {
|
|
|
|
return array();
|
|
|
|
} // not initialized yet
|
2012-12-13 14:59:32 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
$firstCat = $cats->offsetGet(0);
|
|
|
|
$thirdCat = $cats->offsetGet(2);
|
2012-12-13 14:59:32 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
return array(
|
2017-04-26 00:32:02 +02:00
|
|
|
'CalendarDate' => "2017-01-31",
|
2015-12-17 21:20:49 +01:00
|
|
|
'Checkbox' => 1,
|
2016-10-18 12:15:37 +02:00
|
|
|
// 'CheckboxSet' => null,
|
2016-10-18 05:38:41 +02:00
|
|
|
'ConfirmedPassword' => 'secret',
|
2016-10-18 05:32:13 +02:00
|
|
|
'CreditCard' => '4000400040004111',
|
2017-04-26 00:32:02 +02:00
|
|
|
'Date' => "2017-01-31",
|
|
|
|
'DateTime' => "2017-01-31 23:59",
|
|
|
|
'DateTimeWithCalendar' => "2017-01-31 23:59",
|
2016-10-18 05:32:13 +02:00
|
|
|
'DropdownID' => $firstCat->ID,
|
|
|
|
'Email' => 'test@test.com',
|
|
|
|
'GroupedDropdownID' => $firstCat->ID,
|
|
|
|
'HTMLField' => 'My <strong>value</strong> (ä!)',
|
|
|
|
'MoneyAmount' => 99.99,
|
|
|
|
'MoneyCurrency' => 'EUR',
|
2016-10-18 12:15:37 +02:00
|
|
|
// 'ListboxID' => null,
|
2016-06-16 03:11:29 +02:00
|
|
|
'MyCompositeField1' => 'My value (ä!)',
|
|
|
|
'MyCompositeField2' => 'My value (ä!)',
|
|
|
|
'MyCompositeField3' => 'My value (ä!)',
|
|
|
|
'MyCompositeFieldCheckbox' => true,
|
2016-10-18 05:32:13 +02:00
|
|
|
'MyFieldGroup1' => 'My value (ä!)',
|
|
|
|
'MyFieldGroup2' => 'My value (ä!)',
|
|
|
|
'MyFieldGroup3' => 'My value (ä!)',
|
|
|
|
'MyFieldGroupCheckbox' => true,
|
2016-10-18 06:17:35 +02:00
|
|
|
'MyLabelledFieldGroup1' => 'My value (ä!)',
|
|
|
|
'MyLabelledFieldGroup2' => 'My value (ä!)',
|
|
|
|
'MyLabelledFieldGroup3' => 2,
|
|
|
|
'MyLabelledFieldGroupCheckbox' => true,
|
2017-02-15 20:23:09 +01:00
|
|
|
'Number' => 99.123,
|
2016-10-19 21:51:27 +02:00
|
|
|
'OptionSet' => $thirdCat->ID,
|
2016-10-18 05:32:13 +02:00
|
|
|
'Password' => 'My value (ä!)',
|
|
|
|
'PhoneNumber' => '021 1235',
|
|
|
|
'Price' => 99.99,
|
|
|
|
'Readonly' => 'My value (ä!)',
|
|
|
|
'Required' => 'My required value (delete to test)',
|
|
|
|
'Text' => 'My value (ä!)',
|
|
|
|
'Textarea' => 'My value (ä!)',
|
|
|
|
'Time' => "23:59",
|
2017-03-31 03:12:56 +02:00
|
|
|
'TimeHTML5' => "23:59",
|
2016-10-18 06:17:35 +02:00
|
|
|
'ToggleCompositeTextField1' => 'My value (ä!)',
|
2016-10-18 05:32:13 +02:00
|
|
|
'Validated' => '1',
|
2015-12-17 21:20:49 +01:00
|
|
|
);
|
|
|
|
}
|
2016-04-18 23:27:29 +02:00
|
|
|
|
2016-10-19 21:37:06 +02:00
|
|
|
public function Listbox_readonly() {
|
|
|
|
return $this->Listbox();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Listbox_disabled() {
|
|
|
|
return $this->Listbox();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function CheckboxSet_readonly() {
|
|
|
|
return $this->CheckboxSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function CheckboxSet_disabled() {
|
|
|
|
return $this->CheckboxSet();
|
|
|
|
}
|
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
public function getCMSFields()
|
|
|
|
{
|
|
|
|
$fields = parent::getCMSFields();
|
2012-12-13 14:59:32 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
$description = 'This is <strong>bold</strong> help text';
|
2016-07-21 03:29:18 +02:00
|
|
|
$rightTitle = 'This is right title';
|
2016-04-18 23:27:29 +02:00
|
|
|
|
2017-05-18 07:11:01 +02:00
|
|
|
$fields->addFieldsToTab('Root.Text', [
|
|
|
|
Injector::inst()->create(TextField::class, 'Required', 'Required field')
|
2016-07-21 03:29:18 +02:00
|
|
|
->setRightTitle('right title'),
|
2017-05-18 07:11:01 +02:00
|
|
|
Injector::inst()->create(TextField::class, 'Validated', 'Validated field (checks range between 1 and 3)'),
|
|
|
|
Injector::inst()->create(ReadonlyField::class, 'Readonly', 'ReadonlyField'),
|
|
|
|
Injector::inst()->create(TextareaField::class, 'Textarea', 'TextareaField - 8 rows')
|
2015-12-17 21:20:49 +01:00
|
|
|
->setRows(8),
|
2017-05-18 07:11:01 +02:00
|
|
|
Injector::inst()->create(TextField::class, 'Text'),
|
|
|
|
Injector::inst()->create(HTMLEditorField::class, 'HTMLField', 'HTMLField'),
|
|
|
|
Injector::inst()->create(EmailField::class, 'Email'),
|
|
|
|
]);
|
2012-12-13 14:59:32 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
$fields->addFieldsToTab('Root.Numeric', array(
|
2017-05-18 07:11:01 +02:00
|
|
|
Injector::inst()->create(NumericField::class, 'Number')
|
2017-02-15 20:23:09 +01:00
|
|
|
->setScale(4),
|
2017-05-18 07:11:01 +02:00
|
|
|
Injector::inst()->create(CurrencyField::class, 'Price'),
|
|
|
|
Injector::inst()->create(MoneyField::class, 'Money', 'Money', array('Amount' => 99.99, 'Currency' => 'EUR'))
|
2015-12-17 21:20:49 +01:00
|
|
|
));
|
2016-04-18 23:27:29 +02:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
$fields->addFieldsToTab('Root.Option', array(
|
2017-05-18 07:11:01 +02:00
|
|
|
Injector::inst()->create(CheckboxField::class, 'Checkbox'),
|
|
|
|
Injector::inst()->create(CheckboxSetField::class, 'CheckboxSet', 'CheckboxSet', TestCategory::map()),
|
|
|
|
Injector::inst()->create(DropdownField::class, 'DropdownID', 'DropdownField', TestCategory::map())
|
2015-12-17 21:20:49 +01:00
|
|
|
->setHasEmptyDefault(true),
|
2017-05-18 07:11:01 +02:00
|
|
|
Injector::inst()->create(
|
|
|
|
GroupedDropdownField::class,
|
|
|
|
'GroupedDropdownID',
|
|
|
|
'GroupedDropdown',
|
|
|
|
array('Test Categories' => TestCategory::map())
|
2015-12-17 21:20:49 +01:00
|
|
|
),
|
2017-05-18 07:11:01 +02:00
|
|
|
Injector::inst()->create(ListboxField::class, 'Listbox', 'ListboxField (multiple)', TestCategory::map())
|
2015-12-17 21:20:49 +01:00
|
|
|
->setSize(3),
|
2017-05-18 07:11:01 +02:00
|
|
|
Injector::inst()->create(OptionsetField::class, 'OptionSet', 'OptionSetField', TestCategory::map()),
|
|
|
|
Injector::inst()->create(
|
|
|
|
SelectionGroup::class,
|
|
|
|
'SelectionGroup',
|
|
|
|
[
|
|
|
|
new SelectionGroup_Item(
|
|
|
|
'one',
|
|
|
|
TextField::create('SelectionGroupOne', 'one view'),
|
|
|
|
'SelectionGroup Option One'
|
|
|
|
),
|
2016-06-16 03:11:29 +02:00
|
|
|
new SelectionGroup_Item(
|
2017-05-18 07:11:01 +02:00
|
|
|
'two',
|
|
|
|
TextField::create('SelectionGroupOneTwo', 'two view'),
|
|
|
|
'SelectionGroup Option Two'
|
|
|
|
)
|
|
|
|
]
|
|
|
|
),
|
|
|
|
Injector::inst()->create(ToggleCompositeField::class, 'ToggleCompositeField', 'ToggleCompositeField', new FieldList(
|
|
|
|
Injector::inst()->create(TextField::class, 'ToggleCompositeTextField1'),
|
|
|
|
Injector::inst()->create(DropdownField::class, 'ToggleCompositeDropdownField', 'ToggleCompositeDropdownField', TestCategory::map())
|
2015-12-17 21:20:49 +01:00
|
|
|
))
|
|
|
|
));
|
2008-10-03 00:05:45 +02:00
|
|
|
|
2017-04-26 00:32:02 +02:00
|
|
|
$minDate = '2017-01-01';
|
|
|
|
$minDateTime = '2017-01-01 23:59:00';
|
2015-12-17 21:20:49 +01:00
|
|
|
$fields->addFieldsToTab('Root.DateTime', array(
|
2017-05-18 07:11:01 +02:00
|
|
|
Injector::inst()->create(DateField::class, 'CalendarDate', 'DateField with HTML5 (min date: ' . $minDate . ')')
|
2017-04-02 01:26:33 +02:00
|
|
|
->setMinDate($minDate),
|
2017-05-18 07:11:01 +02:00
|
|
|
Injector::inst()->create(DateField::class, 'Date', 'DateField without HTML5 (min date: ' . $minDate . ')')
|
2017-04-26 00:32:02 +02:00
|
|
|
->setHTML5(false)
|
|
|
|
->setMinDate($minDate),
|
2017-05-18 07:11:01 +02:00
|
|
|
Injector::inst()->create(TimeField::class, 'Time', 'TimeField without HTML5')
|
2017-04-02 01:26:33 +02:00
|
|
|
->setHTML5(false),
|
2017-05-18 07:11:01 +02:00
|
|
|
Injector::inst()->create(TimeField::class, 'TimeHTML5', 'TimeField with HTML5'),
|
|
|
|
Injector::inst()->create(DatetimeField::class, 'DateTime', 'DateTime without HTML5 (min date/time: ' . $minDateTime . ')')
|
2017-04-26 00:32:09 +02:00
|
|
|
->setHTML5(false)
|
|
|
|
->setMinDatetime($minDateTime),
|
2017-05-18 07:11:01 +02:00
|
|
|
Injector::inst()->create(DatetimeField::class, 'DateTimeWithCalendar', 'DateTime with HTML5 (min date/time: ' . $minDateTime . ')')
|
2017-04-26 00:32:09 +02:00
|
|
|
->setMinDatetime($minDateTime),
|
2015-12-17 21:20:49 +01:00
|
|
|
));
|
2008-10-03 00:05:45 +02:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
$fields->addFieldsToTab('Root.File', array(
|
2017-07-06 04:20:29 +02:00
|
|
|
$bla = UploadField::create('File', 'UploadField with multiUpload=false (owned by page)')
|
2015-12-17 21:20:49 +01:00
|
|
|
->setDescription($description)
|
2016-07-21 03:29:18 +02:00
|
|
|
->setRightTitle($rightTitle)
|
2017-03-29 22:32:57 +02:00
|
|
|
->setIsMultiUpload(false),
|
2017-07-06 04:20:29 +02:00
|
|
|
UploadField::create('Image', 'UploadField for image (owned by page)')
|
2016-07-21 03:29:18 +02:00
|
|
|
->setDescription($description)
|
|
|
|
->setRightTitle($rightTitle),
|
2015-12-17 21:20:49 +01:00
|
|
|
UploadField::create('HasManyFiles', 'UploadField for has_many')
|
2016-07-21 03:29:18 +02:00
|
|
|
->setRightTitle($rightTitle)
|
2015-12-17 21:20:49 +01:00
|
|
|
->setDescription($description),
|
|
|
|
UploadField::create('ManyManyFiles', 'UploadField for many_many')
|
|
|
|
->setDescription($description)
|
2016-07-21 03:29:18 +02:00
|
|
|
->setRightTitle($rightTitle),
|
2015-12-17 21:20:49 +01:00
|
|
|
));
|
2008-11-13 22:32:37 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
$blacklist = array(
|
2017-04-26 00:31:22 +02:00
|
|
|
'Required', 'Validated', 'ToggleCompositeField', 'SelectionGroup'
|
2015-12-17 21:20:49 +01:00
|
|
|
);
|
2012-12-13 14:59:32 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
$tabs = array('Root.Text', 'Root.Numeric', 'Root.Option', 'Root.DateTime', 'Root.File');
|
|
|
|
foreach ($tabs as $tab) {
|
|
|
|
$tabObj = $fields->fieldByName($tab);
|
|
|
|
foreach ($tabObj->FieldList() as $field) {
|
|
|
|
$field
|
2016-07-21 03:29:18 +02:00
|
|
|
->setDescription($description)
|
2018-12-11 04:05:58 +01:00
|
|
|
->setRightTitle($rightTitle)
|
|
|
|
->addExtraClass('my-extra-class');
|
2012-12-13 14:59:32 +01:00
|
|
|
|
2022-04-13 00:31:07 +02:00
|
|
|
if (in_array($field->getName(), $blacklist ?? [])) {
|
2015-12-17 21:20:49 +01:00
|
|
|
continue;
|
|
|
|
}
|
2012-11-30 12:08:46 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
$disabledField = $field->performDisabledTransformation();
|
|
|
|
$disabledField->setTitle($disabledField->Title() . ' (disabled)');
|
|
|
|
$disabledField->setName($disabledField->getName() . '_disabled');
|
2016-10-18 06:17:35 +02:00
|
|
|
$disabledField->setValue($this->getField($field->getName()));
|
2022-11-09 00:13:52 +01:00
|
|
|
$tabObj->insertAfter($field->getName(), $disabledField);
|
2012-02-29 14:39:11 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
$readonlyField = $field->performReadonlyTransformation();
|
|
|
|
$readonlyField->setTitle($readonlyField->Title() . ' (readonly)');
|
|
|
|
$readonlyField->setName($readonlyField->getName() . '_readonly');
|
2016-10-18 06:17:35 +02:00
|
|
|
$readonlyField->setValue($this->getField($field->getName()));
|
2022-11-09 00:13:52 +01:00
|
|
|
$tabObj->insertAfter($field->getName(), $readonlyField);
|
2015-12-17 21:20:49 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-29 14:39:11 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
$noLabelField = new TextField('Text_NoLabel', false, 'TextField without label');
|
|
|
|
$noLabelField->setDescription($description);
|
2016-07-21 03:29:18 +02:00
|
|
|
$noLabelField->setRightTitle($rightTitle);
|
2015-12-17 21:20:49 +01:00
|
|
|
$fields->addFieldToTab('Root.Text', $noLabelField, 'Text_disabled');
|
2016-07-21 03:29:18 +02:00
|
|
|
|
|
|
|
$fields->addFieldToTab('Root.Text',
|
2016-09-14 06:31:58 +02:00
|
|
|
LabelField::create('SilverStripe\\Forms\\LabelField', 'LabelField')
|
2016-06-16 03:11:29 +02:00
|
|
|
);
|
2016-07-21 03:29:18 +02:00
|
|
|
|
|
|
|
$fields->addFieldToTab('Root.Text',
|
2017-05-18 07:11:01 +02:00
|
|
|
Injector::inst()->create(
|
2016-10-20 11:06:02 +02:00
|
|
|
LiteralField::class,
|
|
|
|
'LiteralField',
|
|
|
|
'<div class="form__divider">LiteralField with <b>some bold text</b> and <a href="http://silverstripe.com">a link</a></div>'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$fields->addFieldToTab('Root.Text',
|
2017-05-18 07:11:01 +02:00
|
|
|
Injector::inst()->create(
|
2016-10-20 11:06:02 +02:00
|
|
|
HTMLReadonlyField::class,
|
|
|
|
'HTMLReadonlyField',
|
|
|
|
'HTMLReadonlyField',
|
|
|
|
'<div class="form__divider">HTMLReadonlyField with <b>some bold text</b></div>'
|
|
|
|
)
|
2016-06-16 03:31:34 +02:00
|
|
|
);
|
2012-03-08 10:36:12 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
$fields->addFieldToTab('Root.Text',
|
|
|
|
FieldGroup::create(
|
|
|
|
TextField::create('MyFieldGroup1'),
|
|
|
|
TextField::create('MyFieldGroup2'),
|
2016-06-16 03:11:29 +02:00
|
|
|
DropdownField::create('MyFieldGroup3', false, TestCategory::map()),
|
|
|
|
CheckboxField::create('MyFieldGroupCheckbox')
|
2015-12-17 21:20:49 +01:00
|
|
|
)
|
2016-07-21 03:29:18 +02:00
|
|
|
->setDescription($description)
|
|
|
|
->setRightTitle($rightTitle)
|
2015-12-17 21:20:49 +01:00
|
|
|
);
|
|
|
|
$fields->addFieldToTab('Root.Text',
|
|
|
|
FieldGroup::create(
|
|
|
|
'MyLabelledFieldGroup',
|
|
|
|
array(
|
|
|
|
TextField::create('MyLabelledFieldGroup1'),
|
|
|
|
TextField::create('MyLabelledFieldGroup2'),
|
2016-06-16 03:11:29 +02:00
|
|
|
DropdownField::create('MyLabelledFieldGroup3', null, TestCategory::map()),
|
|
|
|
CheckboxField::create('MyLabelledFieldGroupCheckbox')
|
2015-12-17 21:20:49 +01:00
|
|
|
)
|
2016-07-21 03:29:18 +02:00
|
|
|
)
|
|
|
|
->setTitle('My Labelled Field Group')
|
|
|
|
->setDescription($description)
|
|
|
|
->setRightTitle($rightTitle)
|
2015-12-17 21:20:49 +01:00
|
|
|
);
|
2016-07-21 03:29:18 +02:00
|
|
|
|
2016-06-16 03:11:29 +02:00
|
|
|
$fields->addFieldToTab('Root.Text',
|
|
|
|
CompositeField::create(
|
|
|
|
TextField::create('MyCompositeField1'),
|
|
|
|
TextField::create('MyCompositeField2'),
|
|
|
|
DropdownField::create('MyCompositeField3', 'MyCompositeField3', TestCategory::map()),
|
|
|
|
CheckboxField::create('MyCompositeFieldCheckbox')
|
|
|
|
)
|
|
|
|
);
|
2013-01-16 10:30:00 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
return $fields;
|
|
|
|
}
|
2008-11-13 22:32:37 +01:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
public function getCMSValidator()
|
|
|
|
{
|
|
|
|
return new RequiredFields('Required');
|
|
|
|
}
|
2013-09-18 13:01:56 +02:00
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
public function validate()
|
|
|
|
{
|
|
|
|
$result = parent::validate();
|
|
|
|
if (!$this->Validated || $this->Validated < 1 || $this->Validated > 3) {
|
|
|
|
$result->error('"Validated" field needs to be between 1 and 3');
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2008-10-03 00:05:45 +02:00
|
|
|
}
|
|
|
|
|
2015-12-17 21:20:49 +01:00
|
|
|
class BasicFieldsTestPage_Controller extends TestPage_Controller
|
|
|
|
{
|
2016-10-18 05:38:41 +02:00
|
|
|
|
2008-10-03 00:05:45 +02:00
|
|
|
}
|