mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Process actions on Form subclasses
Regression introduced through https://github.com/silverstripe/silverstripe-framework/issues/6362. Quote from the RFC: ``` Thus the order of action precedence becomes action callback action on the Form action on the FormRequestHandler action on any parent controller (if given) ```
This commit is contained in:
parent
8ed675d29b
commit
adbf9d9f71
@ -236,6 +236,11 @@ class FormRequestHandler extends RequestHandler
|
|||||||
return $this->$funcName($vars, $this->form, $request);
|
return $this->$funcName($vars, $this->form, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Otherwise, try a handler method on the form itself
|
||||||
|
if ($this->form->hasMethod($funcName)) {
|
||||||
|
return $this->form->$funcName($vars, $this->form, $request);
|
||||||
|
}
|
||||||
|
|
||||||
// Check for inline actions
|
// Check for inline actions
|
||||||
$field = $this->checkFieldsForAction($this->form->Fields(), $funcName);
|
$field = $this->checkFieldsForAction($this->form->Fields(), $funcName);
|
||||||
if ($field) {
|
if ($field) {
|
||||||
|
45
tests/php/Forms/FormRequestHandlerTest.php
Normal file
45
tests/php/Forms/FormRequestHandlerTest.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Forms\Tests;
|
||||||
|
|
||||||
|
use SilverStripe\Control\Controller;
|
||||||
|
use SilverStripe\Control\HTTPRequest;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\Forms\FieldList;
|
||||||
|
use SilverStripe\Forms\FormAction;
|
||||||
|
use SilverStripe\Forms\FormRequestHandler;
|
||||||
|
use SilverStripe\Forms\Tests\FormRequestHandlerTest\TestForm;
|
||||||
|
use SilverStripe\Forms\Tests\FormRequestHandlerTest\TestFormRequestHandler;
|
||||||
|
|
||||||
|
class FormRequestHandlerTest extends SapphireTest
|
||||||
|
{
|
||||||
|
public function testCallsActionOnFormHandler()
|
||||||
|
{
|
||||||
|
$form = new TestForm(
|
||||||
|
new Controller(),
|
||||||
|
'Form',
|
||||||
|
new FieldList(),
|
||||||
|
new FieldList(new FormAction('mySubmitOnFormHandler'))
|
||||||
|
);
|
||||||
|
$form->disableSecurityToken();
|
||||||
|
$handler = new TestFormRequestHandler($form);
|
||||||
|
$request = new HTTPRequest('POST', '/', null, ['action_mySubmitOnFormHandler' => 1]);
|
||||||
|
$response = $handler->httpSubmission($request);
|
||||||
|
$this->assertFalse($response->isError());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCallsActionOnForm()
|
||||||
|
{
|
||||||
|
$form = new TestForm(
|
||||||
|
new Controller(),
|
||||||
|
'Form',
|
||||||
|
new FieldList(),
|
||||||
|
new FieldList(new FormAction('mySubmitOnForm'))
|
||||||
|
);
|
||||||
|
$form->disableSecurityToken();
|
||||||
|
$handler = new FormRequestHandler($form);
|
||||||
|
$request = new HTTPRequest('POST', '/', null, ['action_mySubmitOnForm' => 1]);
|
||||||
|
$response = $handler->httpSubmission($request);
|
||||||
|
$this->assertFalse($response->isError());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Forms\Tests\FormRequestHandlerTest;
|
||||||
|
|
||||||
|
use SilverStripe\Control\HTTPResponse;
|
||||||
|
use SilverStripe\Forms\FormRequestHandler;
|
||||||
|
|
||||||
|
class TestFormRequestHandler extends FormRequestHandler
|
||||||
|
{
|
||||||
|
public function mySubmitOnFormHandler()
|
||||||
|
{
|
||||||
|
return new HTTPResponse('success', 200);
|
||||||
|
}
|
||||||
|
}
|
14
tests/php/Forms/FormRequestHandlerTest/TestForm.php
Normal file
14
tests/php/Forms/FormRequestHandlerTest/TestForm.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\Forms\Tests\FormRequestHandlerTest;
|
||||||
|
|
||||||
|
use SilverStripe\Control\HTTPResponse;
|
||||||
|
use SilverStripe\Forms\Form;
|
||||||
|
|
||||||
|
class TestForm extends Form
|
||||||
|
{
|
||||||
|
public function mySubmitOnForm()
|
||||||
|
{
|
||||||
|
return new HTTPResponse('success', 200);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user