From ba9ec03cfa04dae9e9500747b9ca2a9c55e2e8d1 Mon Sep 17 00:00:00 2001 From: Robert William H Date: Tue, 22 Mar 2016 16:59:55 +0100 Subject: [PATCH] Update FormFlow.php Includes a flag to determine if we should expire the flow on a POST/PUT request, so we can create a flow from a POST/PUT request like this workflow Load Route We do some stuff, for example in AngularJS Once finished our stuff, we submit data to the same controller (or another controller). That controller, handles the data and creates a flow according to submitted data. Flow is rendered. This workflow won't work right now, because every POST/PUT request expires the flow. --- Form/FormFlow.php | 17 ++++++++++++++++- Form/FormFlowInterface.php | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Form/FormFlow.php b/Form/FormFlow.php index e742f69d..a2dd34b5 100644 --- a/Form/FormFlow.php +++ b/Form/FormFlow.php @@ -163,6 +163,13 @@ abstract class FormFlow implements FormFlowInterface { */ private $expired = false; + + /** + * Flow was determined to be expired on post. + * @var boolean + */ + private $expiresOnRequest = true; + /** * Instance ID was a newly generated ID. * @var boolean @@ -639,7 +646,7 @@ protected function bindFlow() { $reset = true; } - if (in_array($this->getRequest()->getMethod(), array('POST', 'PUT')) && !$this->dataManager->exists($this)) { + if ($this->expiresOnRequest && (in_array($this->getRequest()->getMethod(), array('POST', 'PUT')) && !$this->dataManager->exists($this))) { // flow is expired, drop posted data and reset $this->getRequest()->request->replace(); $reset = true; @@ -972,6 +979,14 @@ public function createStepsFromConfig(array $stepsConfig) { return $steps; } + /** + * @param $expires + */ + public function expiresOnRequest($expires) + { + $this->expiresOnRequest = $expires; + } + /** * Defines the configuration for all steps of this flow. * @return array diff --git a/Form/FormFlowInterface.php b/Form/FormFlowInterface.php index 4c9f0648..208e31af 100644 --- a/Form/FormFlowInterface.php +++ b/Form/FormFlowInterface.php @@ -178,4 +178,9 @@ function getSteps(); */ function getStepCount(); + /** + * Toggles expiration on request + * @param $expires + */ + function expiresOnRequest($expires); }