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; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Core\Core; |
17
|
|
|
use Romm\Formz\Exceptions\ContextNotFoundException; |
18
|
|
|
use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService; |
19
|
|
|
use Romm\Formz\Service\ViewHelper\Slot\SlotViewHelperService; |
20
|
|
|
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface; |
21
|
|
|
use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* This view helper registers a slot which will not be rendered directly, but |
25
|
|
|
* with the usage of the `slot.render` view helper. |
26
|
|
|
* |
27
|
|
|
* It is used to manage dynamic parts of the layouts used with the `field` view |
28
|
|
|
* helper: every layout can call as many slots as it needs, and this slots must |
29
|
|
|
* then be registered using this view helper. |
30
|
|
|
*/ |
31
|
|
|
class SlotViewHelper extends AbstractViewHelper implements CompilableInterface |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @inheritdoc |
35
|
|
|
*/ |
36
|
|
|
public function initializeArguments() |
37
|
|
|
{ |
38
|
|
|
parent::initializeArguments(); |
39
|
|
|
|
40
|
|
|
$this->registerArgument('name', 'string', 'Name of the slot.', true); |
41
|
|
|
$this->registerArgument('arguments', 'array', 'Arguments sent to the slot.', false, []); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @inheritdoc |
46
|
|
|
*/ |
47
|
|
|
public function render() |
48
|
|
|
{ |
49
|
|
|
return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritdoc |
54
|
|
|
*/ |
55
|
|
|
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) |
56
|
|
|
{ |
57
|
|
|
/** @var FieldViewHelperService $fieldService */ |
58
|
|
|
$fieldService = Core::instantiate(FieldViewHelperService::class); |
59
|
|
|
|
60
|
|
|
if (false === $fieldService->fieldContextExists()) { |
61
|
|
|
throw ContextNotFoundException::slotViewHelperFieldContextNotFound(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** @var SlotViewHelperService $slotService */ |
65
|
|
|
$slotService = Core::instantiate(SlotViewHelperService::class); |
66
|
|
|
|
67
|
|
|
$slotService->addSlot($arguments['name'], $renderChildrenClosure, $arguments['arguments']); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
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.