mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-06-16 17:51:48 +02:00
Enhancement switch FormFactories to use RequestHandler instead of Controller
This commit is contained in:
parent
403f4db14d
commit
2ee0d99806
|
@ -3,7 +3,7 @@
|
||||||
namespace SilverStripe\Forms;
|
namespace SilverStripe\Forms;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\RequestHandler;
|
||||||
use SilverStripe\Core\Extensible;
|
use SilverStripe\Core\Extensible;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,7 +26,7 @@ class DefaultFormFactory implements FormFactory
|
||||||
$this->constructExtensions();
|
$this->constructExtensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getForm(Controller $controller, $name = FormFactory::DEFAULT_NAME, $context = [])
|
public function getForm(RequestHandler $controller = null, $name = FormFactory::DEFAULT_NAME, $context = [])
|
||||||
{
|
{
|
||||||
// Validate context
|
// Validate context
|
||||||
foreach ($this->getRequiredContext() as $required) {
|
foreach ($this->getRequiredContext() as $required) {
|
||||||
|
@ -52,12 +52,12 @@ class DefaultFormFactory implements FormFactory
|
||||||
/**
|
/**
|
||||||
* Build field list for this form
|
* Build field list for this form
|
||||||
*
|
*
|
||||||
* @param Controller $controller
|
* @param RequestHandler $controller
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $context
|
* @param array $context
|
||||||
* @return FieldList
|
* @return FieldList
|
||||||
*/
|
*/
|
||||||
protected function getFormFields(Controller $controller, $name, $context = [])
|
protected function getFormFields(RequestHandler $controller = null, $name, $context = [])
|
||||||
{
|
{
|
||||||
// Fall back to standard "getCMSFields" which itself uses the FormScaffolder as a fallback
|
// Fall back to standard "getCMSFields" which itself uses the FormScaffolder as a fallback
|
||||||
// @todo Deprecate or formalise support for getCMSFields()
|
// @todo Deprecate or formalise support for getCMSFields()
|
||||||
|
@ -69,12 +69,12 @@ class DefaultFormFactory implements FormFactory
|
||||||
/**
|
/**
|
||||||
* Build list of actions for this form
|
* Build list of actions for this form
|
||||||
*
|
*
|
||||||
* @param Controller $controller
|
* @param RequestHandler $controller
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $context
|
* @param array $context
|
||||||
* @return FieldList
|
* @return FieldList
|
||||||
*/
|
*/
|
||||||
protected function getFormActions(Controller $controller, $name, $context = [])
|
protected function getFormActions(RequestHandler $controller = null, $name, $context = [])
|
||||||
{
|
{
|
||||||
// @todo Deprecate or formalise support for getCMSActions()
|
// @todo Deprecate or formalise support for getCMSActions()
|
||||||
$actions = $context['Record']->getCMSActions();
|
$actions = $context['Record']->getCMSActions();
|
||||||
|
@ -83,12 +83,12 @@ class DefaultFormFactory implements FormFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Controller $controller
|
* @param RequestHandler $controller
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $context
|
* @param array $context
|
||||||
* @return null|Validator
|
* @return null|Validator
|
||||||
*/
|
*/
|
||||||
protected function getFormValidator(Controller $controller, $name, $context = [])
|
protected function getFormValidator(RequestHandler $controller = null, $name, $context = [])
|
||||||
{
|
{
|
||||||
$validator = null;
|
$validator = null;
|
||||||
if ($context['Record']->hasMethod('getCMSValidator')) {
|
if ($context['Record']->hasMethod('getCMSValidator')) {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace SilverStripe\Forms;
|
namespace SilverStripe\Forms;
|
||||||
|
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\RequestHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A service which can generate a form
|
* A service which can generate a form
|
||||||
|
@ -18,14 +18,14 @@ interface FormFactory
|
||||||
/**
|
/**
|
||||||
* Generates the form
|
* Generates the form
|
||||||
*
|
*
|
||||||
* @param Controller $controller Parent controller
|
* @param RequestHandler $controller Parent controller
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $context List of properties which may influence form scaffolding.
|
* @param array $context List of properties which may influence form scaffolding.
|
||||||
* E.g. 'Record' if building a form for a record.
|
* E.g. 'Record' if building a form for a record.
|
||||||
* Custom factories may support more advanced parameters.
|
* Custom factories may support more advanced parameters.
|
||||||
* @return Form
|
* @return Form
|
||||||
*/
|
*/
|
||||||
public function getForm(Controller $controller, $name = self::DEFAULT_NAME, $context = []);
|
public function getForm(RequestHandler $controller = null, $name = self::DEFAULT_NAME, $context = []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return list of mandatory context keys
|
* Return list of mandatory context keys
|
||||||
|
|
Loading…
Reference in New Issue
Block a user