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
105 changes: 62 additions & 43 deletions Form/FormFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,85 +90,85 @@ abstract class FormFlow implements FormFlowInterface {
/**
* @var RequestStack
*/
private $requestStack;
protected $requestStack;

/**
* @var string|null Is only null if not yet initialized.
*/
private $id = null;
protected $id = null;

/**
* @var string|null Is only null if not yet initialized.
*/
private $instanceKey = null;
protected $instanceKey = null;

/**
* @var string|null Is only null if not yet initialized.
*/
private $instanceId = null;
protected $instanceId = null;

/**
* @var string|null Is only null if not yet initialized.
*/
private $formStepKey = null;
protected $formStepKey = null;

/**
* @var string|null Is only null if not yet initialized.
*/
private $formTransitionKey = null;
protected $formTransitionKey = null;

/**
* @var string|null Is only null if not yet initialized.
*/
private $validationGroupPrefix = null;
protected $validationGroupPrefix = null;

/**
* @var StepInterface[]|null Is only null if not yet initialized.
*/
private $steps = null;
protected $steps = null;

/**
* @var int|null Is only null if not yet initialized.
*/
private $stepCount = null;
protected $stepCount = null;

/**
* @var string[]|null Is only null if not yet initialized.
*/
private $stepLabels = null;
protected $stepLabels = null;

/**
* @var mixed|null Is only null if not yet initialized.
*/
private $formData = null;
protected $formData = null;

/**
* @var int|null Is only null if not yet initialized.
*/
private $currentStepNumber = null;
protected $currentStepNumber = null;

/**
* @var FormInterface[]
*/
private $stepForms = array();
protected $stepForms = array();

/**
* Options applied to forms of all steps.
* @var array
*/
private $genericFormOptions = array();
protected $genericFormOptions = array();

/**
* Flow was determined to be expired.
* @var bool
*/
private $expired = false;
protected $expired = false;

/**
* Instance ID was a newly generated ID.
* @var bool
*/
private $newInstance = false;
protected $newInstance = false;

/**
* {@inheritDoc}
Expand Down Expand Up @@ -576,7 +576,7 @@ protected function determineCurrentStepNumber() {
* @param int $stepNumber
* @return int
*/
private function ensureStepNumberRange($stepNumber) {
protected function ensureStepNumberRange($stepNumber) {
return max(min($stepNumber, $this->getStepCount()), 1);
}

Expand Down Expand Up @@ -640,39 +640,50 @@ protected function determineInstanceId() {
return $instanceId;
}

protected function bindFlow() {
$request = $this->getRequest();
$reset = false;
/**
* @return bool
*/
protected function isNeedToResetFlow()
{
$request = $this->getRequest();
$reset = false;

if (!$this->allowDynamicStepNavigation && !$this->allowRedirectAfterSubmit && $request->isMethod('GET')) {
$reset = true;
}
if (!$this->allowDynamicStepNavigation && !$this->allowRedirectAfterSubmit && $request->isMethod('GET')) {
$reset = true;
}

if ($this->getRequestedTransition() === self::TRANSITION_RESET) {
$reset = true;
}
if ($this->getRequestedTransition() === self::TRANSITION_RESET) {
$reset = true;
}

if (in_array($request->getMethod(), array('POST', 'PUT')) && $request->get($this->getFormStepKey()) !== null && !$this->dataManager->exists($this)) {
// flow is expired, drop posted data and reset
$request->request->replace();
$reset = true;
$this->expired = true;
if (in_array($request->getMethod(), array('POST', 'PUT')) && $request->get($this->getFormStepKey()) !== null && !$this->dataManager->exists($this)) {
// flow is expired, drop posted data and reset
$request->request->replace();
$reset = true;
$this->expired = true;

// Regenerate instance ID so resubmits of the form will continue to give error. Otherwise, submitting
// the new form, then backing up to the old form won't give the error.
$this->setInstanceId($this->determineInstanceId());
}
// Regenerate instance ID so resubmits of the form will continue to give error. Otherwise, submitting
// the new form, then backing up to the old form won't give the error.
$this->setInstanceId($this->determineInstanceId());
}

if (!$reset) {
$this->applyDataFromSavedSteps();
}
return $reset;
}

$requestedStepNumber = $this->determineCurrentStepNumber();
protected function bindFlow() {

if ($reset) {
$this->reset();
return;
}
$reset = $this->isNeedToResetFlow();

if (!$reset) {
$this->applyDataFromSavedSteps();
}

$requestedStepNumber = $this->determineCurrentStepNumber();

if ($reset) {
$this->reset();
return;
}

// ensure that the requested step fits the current progress
if ($requestedStepNumber > $this->getFirstStepNumber()) {
Expand Down Expand Up @@ -1094,4 +1105,12 @@ public function hasSkipStep($stepNumber) {
return $this->isStepSkipped($stepNumber);
}

public function isNewInstance() {
return $this->newInstance;
}

public function isExpired() {
return $this->expired;
}

}