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\ViewHelpers\Step; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Exceptions\ContextNotFoundException; |
17
|
|
|
use Romm\Formz\Service\ViewHelper\FormViewHelperService; |
18
|
|
|
use Romm\Formz\ViewHelpers\AbstractViewHelper; |
19
|
|
|
use TYPO3\CMS\Extbase\Mvc\Web\Request; |
20
|
|
|
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface; |
21
|
|
|
use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface; |
22
|
|
|
|
23
|
|
|
class SubstepViewHelper extends AbstractViewHelper implements CompilableInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var FormViewHelperService |
27
|
|
|
*/ |
28
|
|
|
protected $formService; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @inheritdoc |
32
|
|
|
*/ |
33
|
|
|
public function initializeArguments() |
34
|
|
|
{ |
35
|
|
|
$this->registerArgument('identifier', 'string','Identifier of the substep.', true); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function render() |
39
|
|
|
{ |
40
|
|
|
/* |
41
|
|
|
* First, we check if this view helper is called from within the |
42
|
|
|
* `FormViewHelper`, because it would not make sense anywhere else. |
43
|
|
|
*/ |
44
|
|
|
if (false === $this->formService->formContextExists()) { |
45
|
|
|
throw ContextNotFoundException::substepViewHelperFormContextNotFound(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$formObject = $this->formService->getFormObject(); |
49
|
|
|
$formDefinition = $formObject->getDefinition(); |
50
|
|
|
|
51
|
|
|
if (false === $formDefinition->hasSteps()) { |
52
|
|
|
throw new \Exception('todo'); // @todo |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** @var Request $request */ |
56
|
|
|
$request = $this->controllerContext->getRequest(); |
57
|
|
|
$currentStep = $this->formService->getFormObject()->getCurrentStep($request); |
58
|
|
|
|
59
|
|
|
if (false === $currentStep->hasSubsteps()) { |
60
|
|
|
throw new \Exception('todo'); // @todo |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$substeps = $currentStep->getSubsteps(); |
64
|
|
|
|
65
|
|
|
if (false === $substeps->hasEntry($this->arguments['identifier'])) { |
66
|
|
|
throw new \Exception('todo'); // @todo |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @inheritdoc |
74
|
|
|
*/ |
75
|
|
|
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) |
76
|
|
|
{ |
77
|
|
|
return <<<XML |
78
|
|
|
<div fz-substep="{$arguments['identifier']}"> |
79
|
|
|
{$renderChildrenClosure()} |
80
|
|
|
</div> |
81
|
|
|
XML; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param FormViewHelperService $service |
86
|
|
|
*/ |
87
|
|
|
public function injectFormService(FormViewHelperService $service) |
88
|
|
|
{ |
89
|
|
|
$this->formService = $service; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.