2016-12-16 05:34:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Forms\Tests\FormFactoryTest;
|
|
|
|
|
|
|
|
use SilverStripe\Control\Controller;
|
|
|
|
use SilverStripe\Forms\Form;
|
|
|
|
use SilverStripe\ORM\DataObject;
|
2017-03-21 04:22:23 +01:00
|
|
|
use SilverStripe\Versioned\Versioned;
|
2016-12-16 05:34:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit controller for this form
|
|
|
|
*/
|
|
|
|
class TestController extends Controller
|
|
|
|
{
|
|
|
|
private static $extensions = [
|
|
|
|
ControllerExtension::class,
|
|
|
|
];
|
|
|
|
|
|
|
|
public function Link($action = null)
|
|
|
|
{
|
|
|
|
return Controller::join_links(
|
|
|
|
'FormFactoryTest_TestController',
|
|
|
|
$action,
|
|
|
|
'/'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Form()
|
|
|
|
{
|
|
|
|
// Simple example; Just get the first draft record
|
|
|
|
$record = $this->getRecord();
|
2017-05-09 04:09:48 +02:00
|
|
|
$factory = new EditFormFactory();
|
2016-12-16 05:34:21 +01:00
|
|
|
return $factory->getForm($this, 'Form', ['Record' => $record]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function save($data, Form $form)
|
|
|
|
{
|
|
|
|
// Noop
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return DataObject
|
|
|
|
*/
|
|
|
|
protected function getRecord()
|
|
|
|
{
|
|
|
|
return Versioned::get_by_stage(TestObject::class, Versioned::DRAFT)->first();
|
|
|
|
}
|
|
|
|
}
|