Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions Form/FormFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ abstract class FormFlow implements FormFlowInterface {
*/
protected $revalidatePreviousSteps = true;

/**
* @var boolean If this is set to true then step data for the current step will be saved when transitioning backwards.
*/
protected $persistOnBackTransition = false;

/**
* @var boolean
*/
Expand Down Expand Up @@ -347,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;
}
Expand Down Expand Up @@ -494,6 +510,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}
Expand Down Expand Up @@ -667,6 +709,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());
$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
Expand Down