From 0a0ff6e65fcee63bd2795483fa5a91fbfa639bb1 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Fri, 3 Jun 2016 12:45:11 +0100 Subject: [PATCH 01/10] Added optional class property and logic for step data persistance if the flow is transitioned backwards. If persistence on backwards transition is enabled and the current request transition is 'back' then persist the current step data to storage. --- Form/FormFlow.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Form/FormFlow.php b/Form/FormFlow.php index 34edc3ac..2e98a51d 100644 --- a/Form/FormFlow.php +++ b/Form/FormFlow.php @@ -56,6 +56,11 @@ abstract class FormFlow implements FormFlowInterface { */ protected $revalidatePreviousSteps = true; + /** + * @var bool If this is set to true then form data for the current step will be saved when transitioning backwards. + */ + protected $persistOnBackTransition = false; + /** * @var boolean */ @@ -667,6 +672,19 @@ protected function bindFlow() { $this->currentStepNumber = $requestedStepNumber; + if ($this->persistOnBackTransition && $this->getRequestedTransition() === self::TRANSITION_BACK) { + + /** + * If persistence on backwards transition is enabled and the current request transition is 'back' then + * persist the current step data to storage. + */ + $this->nextStep(); + $form = $this->createFormForStep($this->getCurrentStepNumber()); + $form->setData($this->getFormData()); + $this->saveCurrentStepData($form); + $this->previousStep(); + } + if (!$this->allowDynamicStepNavigation && $this->getRequestedTransition() === self::TRANSITION_BACK) { /* * Don't invalidate data for the current step to properly show the filled out form for that step after From efc8b823b44550c72166c60aecebbaac6d43c667 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Fri, 3 Jun 2016 12:48:47 +0100 Subject: [PATCH 02/10] Update FormFlow.php --- Form/FormFlow.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Form/FormFlow.php b/Form/FormFlow.php index 2e98a51d..39ea7a45 100644 --- a/Form/FormFlow.php +++ b/Form/FormFlow.php @@ -56,10 +56,10 @@ abstract class FormFlow implements FormFlowInterface { */ protected $revalidatePreviousSteps = true; - /** - * @var bool If this is set to true then form data for the current step will be saved when transitioning backwards. - */ - protected $persistOnBackTransition = false; + /** + * @var bool If this is set to true then form data for the current step will be saved when transitioning backwards. + */ + protected $persistOnBackTransition = false; /** * @var boolean @@ -672,18 +672,18 @@ protected function bindFlow() { $this->currentStepNumber = $requestedStepNumber; - if ($this->persistOnBackTransition && $this->getRequestedTransition() === self::TRANSITION_BACK) { - - /** - * If persistence on backwards transition is enabled and the current request transition is 'back' then - * persist the current step data to storage. - */ - $this->nextStep(); - $form = $this->createFormForStep($this->getCurrentStepNumber()); - $form->setData($this->getFormData()); - $this->saveCurrentStepData($form); - $this->previousStep(); - } + if ($this->persistOnBackTransition && $this->getRequestedTransition() === self::TRANSITION_BACK) { + + /** + * If persistence on backwards transition is enabled and the current request transition is 'back' then + * persist the current step data to storage. + */ + $this->nextStep(); + $form = $this->createFormForStep($this->getCurrentStepNumber()); + $form->setData($this->getFormData()); + $this->saveCurrentStepData($form); + $this->previousStep(); + } if (!$this->allowDynamicStepNavigation && $this->getRequestedTransition() === self::TRANSITION_BACK) { /* From 12f3046569f73db61e4daf6d7a84faaa67459732 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Fri, 3 Jun 2016 12:49:31 +0100 Subject: [PATCH 03/10] Update FormFlow.php --- Form/FormFlow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Form/FormFlow.php b/Form/FormFlow.php index 39ea7a45..5ef1d1c1 100644 --- a/Form/FormFlow.php +++ b/Form/FormFlow.php @@ -672,7 +672,7 @@ protected function bindFlow() { $this->currentStepNumber = $requestedStepNumber; - if ($this->persistOnBackTransition && $this->getRequestedTransition() === self::TRANSITION_BACK) { + if ($this->persistOnBackTransition && $this->getRequestedTransition() === self::TRANSITION_BACK) { /** * If persistence on backwards transition is enabled and the current request transition is 'back' then From 27edd5867074cb19213218d0e3da14bacdfca3bf Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Fri, 3 Jun 2016 12:52:16 +0100 Subject: [PATCH 04/10] Update FormFlow.php Added previous step. --- Form/FormFlow.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Form/FormFlow.php b/Form/FormFlow.php index 5ef1d1c1..f43881f4 100644 --- a/Form/FormFlow.php +++ b/Form/FormFlow.php @@ -499,6 +499,32 @@ public function nextStep() { return false; // should never be reached, but just in case } + + /** + * {@inheritDoc} + */ + public function previousStep() { + $currentStepNumber = $this->currentStepNumber - 1; + + foreach ($this->getSteps() as $step) { + $step->evaluateSkipping($currentStepNumber, $this); + } + + // There is no "before" step as the target step precedes the first step. + if ($currentStepNumber < $this->getFirstStepNumber()) { + return false; + } + + $currentStepNumber = $this->applySkipping($currentStepNumber); + + if ($currentStepNumber <= $this->getStepCount()) { + $this->currentStepNumber = $currentStepNumber; + + return true; + } + + return false; // should never be reached, but just in case + } /** * {@inheritDoc} From c210ce7578f242a29fb2fb2d26a7ceeab3ff1172 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Fri, 3 Jun 2016 12:53:44 +0100 Subject: [PATCH 05/10] Update FormFlow.php Indented to match file formatting. --- Form/FormFlow.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Form/FormFlow.php b/Form/FormFlow.php index f43881f4..a56cf83b 100644 --- a/Form/FormFlow.php +++ b/Form/FormFlow.php @@ -700,15 +700,15 @@ protected function bindFlow() { if ($this->persistOnBackTransition && $this->getRequestedTransition() === self::TRANSITION_BACK) { - /** - * If persistence on backwards transition is enabled and the current request transition is 'back' then - * persist the current step data to storage. - */ - $this->nextStep(); - $form = $this->createFormForStep($this->getCurrentStepNumber()); - $form->setData($this->getFormData()); - $this->saveCurrentStepData($form); - $this->previousStep(); + /** + * If persistence on backwards transition is enabled and the current request transition is 'back' then + * persist the current step data to storage. + */ + $this->nextStep(); + $form = $this->createFormForStep($this->getCurrentStepNumber()); + $form->setData($this->getFormData()); + $this->saveCurrentStepData($form); + $this->previousStep(); } if (!$this->allowDynamicStepNavigation && $this->getRequestedTransition() === self::TRANSITION_BACK) { From baf241009d41844ece9c772120e9fd4f0d6321ae Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Fri, 3 Jun 2016 12:54:17 +0100 Subject: [PATCH 06/10] Update FormFlow.php --- Form/FormFlow.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Form/FormFlow.php b/Form/FormFlow.php index a56cf83b..9d021c23 100644 --- a/Form/FormFlow.php +++ b/Form/FormFlow.php @@ -512,15 +512,15 @@ public function previousStep() { // There is no "before" step as the target step precedes the first step. if ($currentStepNumber < $this->getFirstStepNumber()) { - return false; + return false; } $currentStepNumber = $this->applySkipping($currentStepNumber); if ($currentStepNumber <= $this->getStepCount()) { - $this->currentStepNumber = $currentStepNumber; + $this->currentStepNumber = $currentStepNumber; - return true; + return true; } return false; // should never be reached, but just in case From 3ef1d6089f2441811919f5b672e9ad56c153fb48 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Fri, 3 Jun 2016 12:59:13 +0100 Subject: [PATCH 07/10] Update FormFlow.php Updated comment to actually match what it does. --- Form/FormFlow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Form/FormFlow.php b/Form/FormFlow.php index 9d021c23..1b611df2 100644 --- a/Form/FormFlow.php +++ b/Form/FormFlow.php @@ -57,7 +57,7 @@ abstract class FormFlow implements FormFlowInterface { protected $revalidatePreviousSteps = true; /** - * @var bool If this is set to true then form data for the current step will be saved when transitioning backwards. + * @var bool If this is set to true then step data for the current step will be saved when transitioning backwards. */ protected $persistOnBackTransition = false; From 0e3e148c2f13e55f5aaf50b8eae3469ae4e21182 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Fri, 3 Jun 2016 13:03:08 +0100 Subject: [PATCH 08/10] Update FormFlow.php Updated comment to match others. --- Form/FormFlow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Form/FormFlow.php b/Form/FormFlow.php index 1b611df2..7127b79d 100644 --- a/Form/FormFlow.php +++ b/Form/FormFlow.php @@ -57,7 +57,7 @@ abstract class FormFlow implements FormFlowInterface { protected $revalidatePreviousSteps = true; /** - * @var bool If this is set to true then step data for the current step will be saved when transitioning backwards. + * @var boolean If this is set to true then step data for the current step will be saved when transitioning backwards. */ protected $persistOnBackTransition = false; From b819d27854e4cf6b154954cbe28c1f202573d6fb Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Fri, 3 Jun 2016 13:40:24 +0100 Subject: [PATCH 09/10] Update FormFlow.php Added setter and is methods for persistOnBackTransition. --- Form/FormFlow.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Form/FormFlow.php b/Form/FormFlow.php index 7127b79d..7978f044 100644 --- a/Form/FormFlow.php +++ b/Form/FormFlow.php @@ -352,6 +352,17 @@ public function isRevalidatePreviousSteps() { return $this->revalidatePreviousSteps; } + public function setPersistOnBackTransition($persistOnBackTransition) { + $this->persistOnBackTransition = (boolean) $persistOnBackTransition; + } + + /** + * {@inheritDoc} + */ + public function isPersistOnBackTransition() { + return $this->persistOnBackTransition; + } + public function setAllowDynamicStepNavigation($allowDynamicStepNavigation) { $this->allowDynamicStepNavigation = (boolean) $allowDynamicStepNavigation; } From 066357d6cf7ae7856545289702c2d1d287a36ed2 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Fri, 3 Jun 2016 13:44:11 +0100 Subject: [PATCH 10/10] Update FormFlow.php Actually don't need to set the form data as it is just getting the form name. --- Form/FormFlow.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Form/FormFlow.php b/Form/FormFlow.php index 7978f044..c5f329fc 100644 --- a/Form/FormFlow.php +++ b/Form/FormFlow.php @@ -717,7 +717,6 @@ protected function bindFlow() { */ $this->nextStep(); $form = $this->createFormForStep($this->getCurrentStepNumber()); - $form->setData($this->getFormData()); $this->saveCurrentStepData($form); $this->previousStep(); }