1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* 2017 Romain CANON <[email protected]> |
4
|
|
|
* |
5
|
|
|
* This file is part of the TYPO3 FormZ project. |
6
|
|
|
* It is free software; you can redistribute it and/or modify it |
7
|
|
|
* under the terms of the GNU General Public License, either |
8
|
|
|
* version 3 of the License, or any later version. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, see: |
11
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Romm\Formz\Middleware\Item\Step; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Middleware\Argument\Arguments; |
17
|
|
|
use Romm\Formz\Middleware\Item\AbstractMiddleware; |
18
|
|
|
use Romm\Formz\Middleware\Item\FormValidation\FormValidationSignal; |
19
|
|
|
use Romm\Formz\Middleware\Item\Step\Service\StepMiddlewareService; |
20
|
|
|
use Romm\Formz\Middleware\Scope\FieldValidationScope; |
21
|
|
|
use Romm\Formz\Middleware\Scope\ReadScope; |
22
|
|
|
use Romm\Formz\Middleware\Signal\Before; |
23
|
|
|
use Romm\Formz\ViewHelpers\Step\PreviousLinkViewHelper; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @todo |
27
|
|
|
*/ |
28
|
|
|
class PreviousStepMiddleware extends AbstractMiddleware implements Before, FormValidationSignal |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
protected $priority = self::PRIORITY_STEP + 100; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var StepMiddlewareService |
37
|
|
|
*/ |
38
|
|
|
protected $service; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
protected static $defaultScopesBlackList = [ReadScope::class, FieldValidationScope::class]; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Inject the step service. |
47
|
|
|
*/ |
48
|
|
|
public function initializeMiddleware() |
49
|
|
|
{ |
50
|
|
|
$this->service = StepMiddlewareService::get(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @see StepFetchingMiddleware |
55
|
|
|
* |
56
|
|
|
* @param Arguments $arguments |
57
|
|
|
*/ |
58
|
|
|
public function before(Arguments $arguments) |
59
|
|
|
{ |
60
|
|
|
$formObject = $this->getFormObject(); |
61
|
|
|
$this->service->reset($formObject, $this->getRequest()); |
62
|
|
|
|
63
|
|
|
if (false === $formObject->getDefinition()->hasSteps()) { |
64
|
|
|
return; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if (!$this->getRequest()->hasArgument(PreviousLinkViewHelper::PREVIOUS_LINK_PARAMETER)) { |
68
|
|
|
return; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$currentStep = $this->getCurrentStep(); |
72
|
|
|
|
73
|
|
|
if ($currentStep) { |
74
|
|
|
$stepDefinition = $this->service->getStepDefinition($currentStep); |
75
|
|
|
|
76
|
|
|
if ($stepDefinition->hasPreviousDefinition()) { |
77
|
|
|
$this->service->redirectToStep($stepDefinition->getPreviousDefinition()->getStep(), $this->redirect()); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|