2016-10-14 03:30:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\Forms\Tests\GridField\GridField_URLHandlerTest;
|
|
|
|
|
|
|
|
use SilverStripe\Control\Controller;
|
|
|
|
use SilverStripe\Control\RequestHandler;
|
|
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
use SilverStripe\Forms\Form;
|
|
|
|
use SilverStripe\Forms\FormAction;
|
|
|
|
use SilverStripe\Forms\GridField\GridField_URLHandler;
|
|
|
|
use SilverStripe\Forms\TextField;
|
|
|
|
use SilverStripe\View\SSViewer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test URLHandler with a nested request handler
|
|
|
|
*/
|
|
|
|
class TestComponent extends RequestHandler implements GridField_URLHandler
|
|
|
|
{
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
private static $allowed_actions = array('Form', 'showform', 'testpage', 'handleItem');
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
protected $gridField;
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function getURLHandlers($gridField)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @skipUpgrade
|
|
|
|
*/
|
|
|
|
return array(
|
|
|
|
'showform' => 'showform',
|
|
|
|
'testpage' => 'testpage',
|
|
|
|
'Form' => 'Form',
|
|
|
|
'item/$ID' => 'handleItem',
|
|
|
|
);
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function handleItem($gridField, $request)
|
|
|
|
{
|
|
|
|
$id = $request->param("ID");
|
|
|
|
return new TestComponent_ItemRequest(
|
|
|
|
$gridField,
|
|
|
|
$id,
|
|
|
|
Controller::join_links($gridField->Link(), 'item/' . $id)
|
|
|
|
);
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function Link()
|
|
|
|
{
|
|
|
|
return $this->gridField->Link();
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function showform($gridField, $request)
|
|
|
|
{
|
|
|
|
return "<head>" . SSViewer::get_base_tag("") . "</head>" . $this->Form($gridField, $request)->forTemplate();
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function Form($gridField, $request)
|
|
|
|
{
|
|
|
|
$this->gridField = $gridField;
|
|
|
|
/**
|
|
|
|
* @skipUpgrade
|
|
|
|
*/
|
|
|
|
return new Form(
|
|
|
|
$this,
|
|
|
|
'Form',
|
|
|
|
new FieldList(
|
|
|
|
new TextField("Test")
|
|
|
|
),
|
|
|
|
new FieldList(
|
|
|
|
new FormAction('doAction', 'Go')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function doAction($data, $form)
|
|
|
|
{
|
|
|
|
return "Submitted " . $data['Test'] . " to component";
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testpage($gridField, $request)
|
|
|
|
{
|
|
|
|
return "Test page for component";
|
|
|
|
}
|
2016-10-14 03:30:05 +02:00
|
|
|
}
|