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\Form\FormObject\FormObjectFactory; |
17
|
|
|
use Romm\Formz\Middleware\Argument\Arguments; |
18
|
|
|
use Romm\Formz\Middleware\Item\AbstractMiddleware; |
19
|
|
|
use Romm\Formz\Middleware\Item\FormInjection\FormInjectionSignal; |
20
|
|
|
use Romm\Formz\Middleware\Item\Step\Service\StepMiddlewareService; |
21
|
|
|
use Romm\Formz\Middleware\Processor\PresetMiddlewareInterface; |
22
|
|
|
use Romm\Formz\Middleware\Scope\FieldValidationScope; |
23
|
|
|
use Romm\Formz\Middleware\Scope\ReadScope; |
24
|
|
|
use Romm\Formz\Middleware\Signal\After; |
25
|
|
|
use Romm\Formz\ViewHelpers\Step\PreviousLinkViewHelper; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @todo |
29
|
|
|
*/ |
30
|
|
|
class PreviousStepMiddleware extends AbstractMiddleware implements After, FormInjectionSignal, PresetMiddlewareInterface |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @var int |
34
|
|
|
*/ |
35
|
|
|
protected $priority = self::PRIORITY_STEP_FETCHING + 100; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var StepMiddlewareService |
39
|
|
|
*/ |
40
|
|
|
protected $service; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
protected static $defaultScopesBlackList = [ReadScope::class, FieldValidationScope::class]; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Inject the step service. |
49
|
|
|
*/ |
50
|
|
|
public function initializeMiddleware() |
51
|
|
|
{ |
52
|
|
|
$this->service = StepMiddlewareService::get(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @see PreviousStepMiddleware |
57
|
|
|
* |
58
|
|
|
* @param Arguments $arguments |
59
|
|
|
*/ |
60
|
|
|
public function after(Arguments $arguments) |
61
|
|
|
{ |
62
|
|
|
$formObject = $this->getFormObject(); |
63
|
|
|
$this->service->reset($formObject, $this->getRequest()); |
64
|
|
|
|
65
|
|
|
if (false === $formObject->getDefinition()->hasSteps()) { |
66
|
|
|
return; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (!$this->getRequest()->hasArgument(PreviousLinkViewHelper::PREVIOUS_LINK_PARAMETER)) { |
70
|
|
|
return; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$currentStep = $this->getCurrentStep(); |
74
|
|
|
|
75
|
|
|
if ($currentStep) { |
76
|
|
|
$stepDefinition = $this->service->getStepDefinition($currentStep); |
77
|
|
|
|
78
|
|
|
if ($currentStep->hasSubsteps()) { |
79
|
|
|
$stepService = FormObjectFactory::get()->getStepService($this->getFormObject()); |
80
|
|
|
$substepsLevel = $stepService->getSubstepsLevel(); |
81
|
|
|
|
82
|
|
|
if ($substepsLevel > 1) { |
83
|
|
|
$substepDefinition = $currentStep->getSubsteps()->getFirstSubstepDefinition(); |
84
|
|
|
|
85
|
|
|
while ($substepDefinition) { |
86
|
|
|
$nextSubstepDefinition = $this->service->getNextSubstepDefinition($substepDefinition); |
87
|
|
|
|
88
|
|
|
if (!$nextSubstepDefinition |
89
|
|
|
|| $nextSubstepDefinition->getLevel() >= $substepsLevel - 1 |
90
|
|
|
) { |
91
|
|
|
break; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$substepDefinition = $nextSubstepDefinition; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$stepService->setCurrentSubstepDefinition($substepDefinition); |
98
|
|
|
$stepService->setCurrentStep($currentStep); |
99
|
|
|
$stepService->setSubstepsLevel($substepDefinition->getLevel()); |
100
|
|
|
// \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($substepDefinition, __CLASS__ . ':' . __LINE__ . ' $substepDefinition'); |
101
|
|
|
// \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($substepDefinition->getLevel(), __CLASS__ . ':' . __LINE__ . ' $substepDefinition->getLevel()'); |
102
|
|
|
// \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($currentStep, __CLASS__ . ':' . __LINE__ . ' $currentStep'); |
103
|
|
|
// \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($stepService, __CLASS__ . ':' . __LINE__ . ' $stepService'); |
104
|
|
|
// die(); |
105
|
|
|
|
106
|
|
|
return; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
if ($stepDefinition->hasPreviousDefinition()) { |
112
|
|
|
$this->service->redirectToStep($stepDefinition->getPreviousDefinition()->getStep(), $this->redirect()); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|