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\Field\Focus; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Form\Definition\Field\Field; |
17
|
|
|
use Romm\Formz\Form\Definition\Step\Step\Step; |
18
|
|
|
use Romm\Formz\Form\Definition\Step\Step\Substep\Substep; |
19
|
|
|
use Romm\Formz\Form\Definition\Step\Step\Substep\SubstepDefinition; |
20
|
|
|
use Romm\Formz\Form\FormObject\FormObjectFactory; |
21
|
|
|
use Romm\Formz\Middleware\Item\OnBeginMiddleware; |
22
|
|
|
use Romm\Formz\Middleware\Processor\PresetMiddlewareInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @todo |
26
|
|
|
*/ |
27
|
|
|
class FieldFocusMiddleware extends OnBeginMiddleware implements PresetMiddlewareInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var Step |
31
|
|
|
*/ |
32
|
|
|
protected $step; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var Field |
36
|
|
|
*/ |
37
|
|
|
protected $field; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @todo |
41
|
|
|
*/ |
42
|
|
|
protected function process() |
43
|
|
|
{ |
44
|
|
|
return; |
45
|
|
|
|
46
|
|
|
if ($this->getFormObject()->formWasSubmitted()) { |
|
|
|
|
47
|
|
|
return; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$this->step = $this->getCurrentStep(); |
51
|
|
|
|
52
|
|
|
if (!$this->step) { |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if (false === $this->step->hasSubsteps()) { |
57
|
|
|
return; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->fetchField(); |
61
|
|
|
|
62
|
|
|
if (null === $this->field) { |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$firstSubstepDefinition = $this->step->getSubsteps()->getFirstSubstepDefinition(); |
67
|
|
|
$substepDefinition = $this->fetchFieldSubstep($firstSubstepDefinition); |
68
|
|
|
|
69
|
|
|
$stepService = FormObjectFactory::get()->getStepService($this->getFormObject()); |
70
|
|
|
$stepService->setCurrentSubstepDefinition($substepDefinition); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param SubstepDefinition $substepDefinition |
75
|
|
|
* @return SubstepDefinition|null |
76
|
|
|
*/ |
77
|
|
|
protected function fetchFieldSubstep(SubstepDefinition $substepDefinition) |
78
|
|
|
{ |
79
|
|
|
if ($substepDefinition->getSubstep()->supportsField($this->field)) { |
80
|
|
|
return $substepDefinition; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if ($substepDefinition->hasNextSubstep()) { |
84
|
|
|
return $this->fetchFieldSubstep($substepDefinition->getNextSubstep()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return null; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
protected function fetchField() |
91
|
|
|
{ |
92
|
|
|
$fieldName = 'nom'; |
93
|
|
|
$formDefinition = $this->getFormObject()->getDefinition(); |
94
|
|
|
|
95
|
|
|
if ($formDefinition->hasField($fieldName)) { |
96
|
|
|
$field = $formDefinition->getField($fieldName); |
97
|
|
|
|
98
|
|
|
if ($this->step->supportsField($field)) { |
99
|
|
|
$this->field = $field; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.