|
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\ViewHelpers\Service\FieldService; |
|
18
|
|
|
use Romm\Formz\ViewHelpers\Service\SectionService; |
|
19
|
|
|
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface; |
|
20
|
|
|
use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* This view helper registers a section which will not be rendered directly, but |
|
24
|
|
|
* with the usage of the `RenderSection` view helper. |
|
25
|
|
|
* |
|
26
|
|
|
* It is used to manage dynamic parts of the layouts used with the `field` view |
|
27
|
|
|
* helper: every layout can call as many sections as it needs, and this sections |
|
28
|
|
|
* must then be registered using this view helper. |
|
29
|
|
|
*/ |
|
30
|
|
|
class SectionViewHelper extends AbstractViewHelper implements CompilableInterface |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var FieldService |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $fieldService; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @inheritdoc |
|
39
|
|
|
*/ |
|
40
|
|
|
public function initializeArguments() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->registerArgument('name', 'string', 'Name of the section.', true); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @inheritdoc |
|
47
|
|
|
*/ |
|
48
|
|
|
public function render() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->fieldService->checkIsInsideFieldViewHelper(); |
|
51
|
|
|
|
|
52
|
|
|
return self::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @inheritdoc |
|
57
|
|
|
*/ |
|
58
|
|
|
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) |
|
59
|
|
|
{ |
|
60
|
|
|
/** @var SectionService $sectionService */ |
|
61
|
|
|
$sectionService = Core::instantiate(SectionService::class); |
|
62
|
|
|
|
|
63
|
|
|
$sectionService->addSectionClosure($arguments['name'], $renderChildrenClosure); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param FieldService $service |
|
68
|
|
|
*/ |
|
69
|
|
|
public function injectFieldService(FieldService $service) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->fieldService = $service; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|