Remove object class

This commit is contained in:
Damian Mooyman 2017-05-18 17:11:01 +12:00
parent b0ade69057
commit 02e932f3e5
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
5 changed files with 76 additions and 62 deletions

View File

@ -1,10 +1,26 @@
<?php <?php
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;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\FrameworkTest\Model\TestCategory; use SilverStripe\FrameworkTest\Model\TestCategory;
use SilverStripe\FrameworkTest\Model\TestPage; use SilverStripe\FrameworkTest\Model\TestPage;
use SilverStripe\FrameworkTest\Model\TestPage_Controller; use SilverStripe\FrameworkTest\Model\TestPage_Controller;
use SilverStripe\Core\Object;
use SilverStripe\Forms\TextField; use SilverStripe\Forms\TextField;
use SilverStripe\Forms\SelectionGroup_Item; use SilverStripe\Forms\SelectionGroup_Item;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
@ -180,70 +196,76 @@ class BasicFieldsTestPage extends TestPage
$description = 'This is <strong>bold</strong> help text'; $description = 'This is <strong>bold</strong> help text';
$rightTitle = 'This is right title'; $rightTitle = 'This is right title';
$fields->addFieldsToTab('Root.Text', array( $fields->addFieldsToTab('Root.Text', [
Object::create('SilverStripe\\Forms\\TextField', 'Required', 'Required field') Injector::inst()->create(TextField::class, 'Required', 'Required field')
->setRightTitle('right title'), ->setRightTitle('right title'),
Object::create('SilverStripe\\Forms\\TextField', 'Validated', 'Validated field (checks range between 1 and 3)'), Injector::inst()->create(TextField::class, 'Validated', 'Validated field (checks range between 1 and 3)'),
Object::create('SilverStripe\\Forms\\ReadonlyField', 'Readonly', 'ReadonlyField'), Injector::inst()->create(ReadonlyField::class, 'Readonly', 'ReadonlyField'),
Object::create('SilverStripe\\Forms\\TextareaField', 'Textarea', 'TextareaField - 8 rows') Injector::inst()->create(TextareaField::class, 'Textarea', 'TextareaField - 8 rows')
->setRows(8), ->setRows(8),
Object::create('SilverStripe\\Forms\\TextField', 'Text'), Injector::inst()->create(TextField::class, 'Text'),
Object::create('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField', 'HTMLField', 'HTMLField'), Injector::inst()->create(HTMLEditorField::class, 'HTMLField', 'HTMLField'),
Object::create('SilverStripe\\Forms\\EmailField', 'Email'), Injector::inst()->create(EmailField::class, 'Email'),
// Object::create('SilverStripe\\Forms\\ConfirmedPasswordField', 'ConfirmedPassword') ]);
));
$fields->addFieldsToTab('Root.Numeric', array( $fields->addFieldsToTab('Root.Numeric', array(
Object::create('SilverStripe\\Forms\\NumericField', 'Number') Injector::inst()->create(NumericField::class, 'Number')
->setScale(4), ->setScale(4),
Object::create('SilverStripe\\Forms\\CurrencyField', 'Price'), Injector::inst()->create(CurrencyField::class, 'Price'),
Object::create('SilverStripe\\Forms\\MoneyField', 'Money', 'Money', array('Amount' => 99.99, 'Currency' => 'EUR')) Injector::inst()->create(MoneyField::class, 'Money', 'Money', array('Amount' => 99.99, 'Currency' => 'EUR'))
)); ));
$fields->addFieldsToTab('Root.Option', array( $fields->addFieldsToTab('Root.Option', array(
Object::create('SilverStripe\\Forms\\CheckboxField', 'Checkbox'), Injector::inst()->create(CheckboxField::class, 'Checkbox'),
Object::create('SilverStripe\\Forms\\CheckboxSetField', 'CheckboxSet', 'CheckboxSet', TestCategory::map()), Injector::inst()->create(CheckboxSetField::class, 'CheckboxSet', 'CheckboxSet', TestCategory::map()),
Object::create('SilverStripe\\Forms\\DropdownField', 'DropdownID', 'DropdownField', TestCategory::map()) Injector::inst()->create(DropdownField::class, 'DropdownID', 'DropdownField', TestCategory::map())
->setHasEmptyDefault(true), ->setHasEmptyDefault(true),
Object::create('SilverStripe\\Forms\\GroupedDropdownField', 'GroupedDropdownID', Injector::inst()->create(
'GroupedDropdown', array('Test Categories' => TestCategory::map()) GroupedDropdownField::class,
'GroupedDropdownID',
'GroupedDropdown',
array('Test Categories' => TestCategory::map())
), ),
Object::create('SilverStripe\\Forms\\ListboxField', 'Listbox', 'ListboxField (multiple)', TestCategory::map()) Injector::inst()->create(ListboxField::class, 'Listbox', 'ListboxField (multiple)', TestCategory::map())
->setSize(3), ->setSize(3),
Object::create('SilverStripe\\Forms\\OptionsetField', 'OptionSet', 'OptionSetField', TestCategory::map()), Injector::inst()->create(OptionsetField::class, 'OptionSet', 'OptionSetField', TestCategory::map()),
Object::create('SilverStripe\\Forms\\SelectionGroup', 'SelectionGroup', array( Injector::inst()->create(
new SelectionGroup_Item( SelectionGroup::class,
'one', 'SelectionGroup',
TextField::create('SelectionGroupOne', 'one view'), [
'SelectionGroup Option One'
),
new SelectionGroup_Item( new SelectionGroup_Item(
'two', 'one',
TextField::create('SelectionGroupOneTwo', 'two view'), TextField::create('SelectionGroupOne', 'one view'),
'SelectionGroup Option Two' 'SelectionGroup Option One'
) ),
)), new SelectionGroup_Item(
Object::create('SilverStripe\\Forms\\ToggleCompositeField', 'ToggleCompositeField', 'ToggleCompositeField', new FieldList( 'two',
Object::create('SilverStripe\\Forms\\TextField', 'ToggleCompositeTextField1'), TextField::create('SelectionGroupOneTwo', 'two view'),
Object::create('SilverStripe\\Forms\\DropdownField', 'ToggleCompositeDropdownField', 'ToggleCompositeDropdownField', TestCategory::map()) '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())
)) ))
)); ));
$minDate = '2017-01-01'; $minDate = '2017-01-01';
$minDateTime = '2017-01-01 23:59:00'; $minDateTime = '2017-01-01 23:59:00';
$fields->addFieldsToTab('Root.DateTime', array( $fields->addFieldsToTab('Root.DateTime', array(
Object::create('SilverStripe\\Forms\\DateField', 'CalendarDate', 'DateField with HTML5 (min date: ' . $minDate . ')') Injector::inst()->create(DateField::class, 'CalendarDate', 'DateField with HTML5 (min date: ' . $minDate . ')')
->setMinDate($minDate), ->setMinDate($minDate),
Object::create('SilverStripe\\Forms\\DateField', 'Date', 'DateField without HTML5 (min date: ' . $minDate . ')') Injector::inst()->create(DateField::class, 'Date', 'DateField without HTML5 (min date: ' . $minDate . ')')
->setHTML5(false) ->setHTML5(false)
->setMinDate($minDate), ->setMinDate($minDate),
Object::create('SilverStripe\\Forms\\TimeField', 'Time', 'TimeField without HTML5') Injector::inst()->create(TimeField::class, 'Time', 'TimeField without HTML5')
->setHTML5(false), ->setHTML5(false),
Object::create('SilverStripe\\Forms\\TimeField', 'TimeHTML5', 'TimeField with HTML5'), Injector::inst()->create(TimeField::class, 'TimeHTML5', 'TimeField with HTML5'),
Object::create('SilverStripe\\Forms\\DatetimeField', 'DateTime', 'DateTime without HTML5 (min date/time: ' . $minDateTime . ')') Injector::inst()->create(DatetimeField::class, 'DateTime', 'DateTime without HTML5 (min date/time: ' . $minDateTime . ')')
->setHTML5(false) ->setHTML5(false)
->setMinDatetime($minDateTime), ->setMinDatetime($minDateTime),
Object::create('SilverStripe\\Forms\\DatetimeField', 'DateTimeWithCalendar', 'DateTime with HTML5 (min date/time: ' . $minDateTime . ')') Injector::inst()->create(DatetimeField::class, 'DateTimeWithCalendar', 'DateTime with HTML5 (min date/time: ' . $minDateTime . ')')
->setMinDatetime($minDateTime), ->setMinDatetime($minDateTime),
)); ));
@ -252,10 +274,6 @@ class BasicFieldsTestPage extends TestPage
->setDescription($description) ->setDescription($description)
->setRightTitle($rightTitle) ->setRightTitle($rightTitle)
->setIsMultiUpload(false), ->setIsMultiUpload(false),
// UploadField::create('AttachedFile', 'UploadField with canUpload=false')
// ->setDescription($description)
// ->setRightTitle($rightTitle)
// ->setConfig('canUpload', false),
UploadField::create('Image', 'UploadField for image') UploadField::create('Image', 'UploadField for image')
->setDescription($description) ->setDescription($description)
->setRightTitle($rightTitle), ->setRightTitle($rightTitle),
@ -308,7 +326,7 @@ class BasicFieldsTestPage extends TestPage
); );
$fields->addFieldToTab('Root.Text', $fields->addFieldToTab('Root.Text',
Object::create( Injector::inst()->create(
LiteralField::class, LiteralField::class,
'LiteralField', 'LiteralField',
'<div class="form__divider">LiteralField with <b>some bold text</b> and <a href="http://silverstripe.com">a link</a></div>' '<div class="form__divider">LiteralField with <b>some bold text</b> and <a href="http://silverstripe.com">a link</a></div>'
@ -316,7 +334,7 @@ class BasicFieldsTestPage extends TestPage
); );
$fields->addFieldToTab('Root.Text', $fields->addFieldToTab('Root.Text',
Object::create( Injector::inst()->create(
HTMLReadonlyField::class, HTMLReadonlyField::class,
'HTMLReadonlyField', 'HTMLReadonlyField',
'HTMLReadonlyField', 'HTMLReadonlyField',

View File

@ -36,10 +36,9 @@ class TestCategory extends DataObject
public function requireDefaultRecords() public function requireDefaultRecords()
{ {
$class = $this->class; if (!DataObject::get_one(static::class)) {
if (!DataObject::get_one($class)) {
foreach (array("A", "B", "C", "D") as $item) { foreach (array("A", "B", "C", "D") as $item) {
$page = new $class(); $page = new static();
$page->Title = "Test Category $item"; $page->Title = "Test Category $item";
$page->write(); $page->write();
} }

View File

@ -31,14 +31,13 @@ class TestPage extends Page
public function requireDefaultRecords() public function requireDefaultRecords()
{ {
if ($this->class == 'SilverStripe\\FrameworkTest\\Model\\TestPage') { if (static::class === self::class) {
return; return;
} }
$class = $this->class; if (!DataObject::get_one(static::class)) {
if (!DataObject::get_one($class)) {
// Try to create common parent // Try to create common parent
Member::actAs(Security::findAnAdministrator(), function () use ($class) { Member::actAs(Security::findAnAdministrator(), function () {
$parent = SiteTree::get() $parent = SiteTree::get()
->filter('URLSegment', 'feature-test-pages') ->filter('URLSegment', 'feature-test-pages')
->First(); ->First();
@ -54,8 +53,8 @@ class TestPage extends Page
} }
// Create actual page // Create actual page
$page = new $class(); $page = new static();
$page->Title = str_replace("SilverStripe\\FrameworkTest\\Model\\TestPage", "", $class); $page->Title = str_replace(self::class, "", static::class);
$page->ShowInMenus = 0; $page->ShowInMenus = 0;
if ($parent) { if ($parent) {
$page->ParentID = $parent->ID; $page->ParentID = $parent->ID;

View File

@ -17,7 +17,7 @@ class Page2MultiForm extends MultiForm
$steps = DataObject::get('MultiFormStep', "SessionID = {$this->session->ID}"); $steps = DataObject::get('MultiFormStep', "SessionID = {$this->session->ID}");
if ($steps) { if ($steps) {
foreach ($steps as $step) { foreach ($steps as $step) {
if ($step->class == 'Page2PersonalDetailsFormStep') { if ($step->ClassName == 'Page2PersonalDetailsFormStep') {
$member = new Member(); $member = new Member();
$data = $step->loadData(); $data = $step->loadData();
if ($data) { if ($data) {
@ -26,7 +26,7 @@ class Page2MultiForm extends MultiForm
} }
} }
if ($step->class == 'Page2OrganisationDetailsFormStep') { if ($step->ClassName == 'Page2OrganisationDetailsFormStep') {
$organisation = new Organisation(); $organisation = new Organisation();
$data = $step->loadData(); $data = $step->loadData();
if ($data) { if ($data) {

View File

@ -7,10 +7,8 @@ use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField; use SilverStripe\Forms\TextField;
class Page3MultiForm extends MultiForm class Page3MultiForm extends MultiForm
{ {
public static $start_step = 'Page3StartFormStep'; public static $start_step = 'Page3StartFormStep';
public function finish($data, $form) public function finish($data, $form)
@ -19,7 +17,7 @@ class Page3MultiForm extends MultiForm
$steps = DataObject::get('MultiFormStep', "SessionID = {$this->session->ID}"); $steps = DataObject::get('MultiFormStep', "SessionID = {$this->session->ID}");
if ($steps) { if ($steps) {
foreach ($steps as $step) { foreach ($steps as $step) {
if ($step->class == 'Page3PersonalDetailsFormStep') { if ($step->ClassName == 'Page3PersonalDetailsFormStep') {
$member = new Member(); $member = new Member();
$data = $step->loadData(); $data = $step->loadData();
if ($data) { if ($data) {
@ -28,7 +26,7 @@ class Page3MultiForm extends MultiForm
} }
} }
if ($step->class == 'Page3OrganisationDetailsFormStep') { if ($step->ClassName == 'Page3OrganisationDetailsFormStep') {
$organisation = new Organisation(); $organisation = new Organisation();
$data = $step->loadData(); $data = $step->loadData();
if ($data) { if ($data) {