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\Slot; |
15
|
|
|
|
16
|
|
|
use Closure; |
17
|
|
|
use Romm\Formz\Core\Core; |
18
|
|
|
use Romm\Formz\Exceptions\ContextNotFoundException; |
19
|
|
|
use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; |
20
|
|
|
use Romm\Formz\Service\ViewHelper\Slot\SlotViewHelperService; |
21
|
|
|
use Romm\Formz\ViewHelpers\AbstractViewHelper; |
22
|
|
|
use TYPO3\CMS\Core\Utility\ArrayUtility; |
23
|
|
|
use TYPO3\CMS\Core\Utility\VersionNumberUtility; |
24
|
|
|
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface; |
25
|
|
|
use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* This is the rendering function for the `slot` view helper. |
29
|
|
|
* |
30
|
|
|
* @see \Romm\Formz\ViewHelpers\SlotViewHelper |
31
|
|
|
*/ |
32
|
|
|
class RenderViewHelper extends AbstractViewHelper implements CompilableInterface |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var bool |
36
|
|
|
*/ |
37
|
|
|
protected $escapeOutput = false; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @inheritdoc |
41
|
|
|
*/ |
42
|
|
|
public function initializeArguments() |
43
|
|
|
{ |
44
|
|
|
$this->registerArgument('slot', 'string', 'Instance of the slot which will be rendered.', true); |
45
|
|
|
$this->registerArgument('arguments', 'array', 'Arguments sent to the slot.', false, []); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @inheritdoc |
50
|
|
|
*/ |
51
|
|
|
public function render() |
52
|
|
|
{ |
53
|
|
|
parent::initializeArguments(); |
|
|
|
|
54
|
|
|
|
55
|
|
|
return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Will render the slot with the given name, only if the slot is found. |
60
|
|
|
* |
61
|
|
|
* @inheritdoc |
62
|
|
|
*/ |
63
|
|
|
public static function renderStatic(array $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) |
64
|
|
|
{ |
65
|
|
|
/** @var FieldViewHelperService $fieldService */ |
66
|
|
|
$fieldService = Core::instantiate(FieldViewHelperService::class); |
67
|
|
|
|
68
|
|
|
if (false === $fieldService->fieldContextExists()) { |
69
|
|
|
throw ContextNotFoundException::slotRenderViewHelperFieldContextNotFound(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** @var SlotViewHelperService $slotService */ |
73
|
|
|
$slotService = Core::instantiate(SlotViewHelperService::class); |
74
|
|
|
$slotName = $arguments['slot']; |
75
|
|
|
$result = ''; |
76
|
|
|
|
77
|
|
|
if ($slotService->hasSlot($slotName)) { |
78
|
|
|
$currentVariables = version_compare(VersionNumberUtility::getCurrentTypo3Version(), '8.0.0', '<') |
79
|
|
|
? $renderingContext->getTemplateVariableContainer()->getAll() |
|
|
|
|
80
|
|
|
: $renderingContext->getVariableProvider()->getAll(); |
81
|
|
|
|
82
|
|
|
ArrayUtility::mergeRecursiveWithOverrule($currentVariables, $arguments['arguments']); |
83
|
|
|
|
84
|
|
|
$slotService->addTemplateVariables($slotName, $currentVariables); |
85
|
|
|
|
86
|
|
|
$slotClosure = $slotService->getSlotClosure($slotName); |
87
|
|
|
$result = $slotClosure(); |
88
|
|
|
|
89
|
|
|
$slotService->restoreTemplateVariables($slotName); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $result; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.