Enhancement switch FormFactories to use RequestHandler instead of Controller

This commit is contained in:
Christopher Joe 2017-05-04 14:07:51 +12:00 committed by Sam Minnée
parent 403f4db14d
commit 2ee0d99806
2 changed files with 11 additions and 11 deletions

View File

@ -3,7 +3,7 @@
namespace SilverStripe\Forms;
use InvalidArgumentException;
use SilverStripe\Control\Controller;
use SilverStripe\Control\RequestHandler;
use SilverStripe\Core\Extensible;
/**
@ -26,7 +26,7 @@ class DefaultFormFactory implements FormFactory
$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
foreach ($this->getRequiredContext() as $required) {
@ -52,12 +52,12 @@ class DefaultFormFactory implements FormFactory
/**
* Build field list for this form
*
* @param Controller $controller
* @param RequestHandler $controller
* @param string $name
* @param array $context
* @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
// @todo Deprecate or formalise support for getCMSFields()
@ -69,12 +69,12 @@ class DefaultFormFactory implements FormFactory
/**
* Build list of actions for this form
*
* @param Controller $controller
* @param RequestHandler $controller
* @param string $name
* @param array $context
* @return FieldList
*/
protected function getFormActions(Controller $controller, $name, $context = [])
protected function getFormActions(RequestHandler $controller = null, $name, $context = [])
{
// @todo Deprecate or formalise support for getCMSActions()
$actions = $context['Record']->getCMSActions();
@ -83,12 +83,12 @@ class DefaultFormFactory implements FormFactory
}
/**
* @param Controller $controller
* @param RequestHandler $controller
* @param string $name
* @param array $context
* @return null|Validator
*/
protected function getFormValidator(Controller $controller, $name, $context = [])
protected function getFormValidator(RequestHandler $controller = null, $name, $context = [])
{
$validator = null;
if ($context['Record']->hasMethod('getCMSValidator')) {

View File

@ -2,7 +2,7 @@
namespace SilverStripe\Forms;
use SilverStripe\Control\Controller;
use SilverStripe\Control\RequestHandler;
/**
* A service which can generate a form
@ -18,14 +18,14 @@ interface FormFactory
/**
* Generates the form
*
* @param Controller $controller Parent controller
* @param RequestHandler $controller Parent controller
* @param string $name
* @param array $context List of properties which may influence form scaffolding.
* E.g. 'Record' if building a form for a record.
* Custom factories may support more advanced parameters.
* @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