|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the TYPO3 CMS project. |
|
7
|
|
|
* |
|
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
10
|
|
|
* of the License, or any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* For the full copyright and license information, please read the |
|
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
14
|
|
|
* |
|
15
|
|
|
* The TYPO3 project - inspiring people to share! |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Backend\ViewHelpers; |
|
19
|
|
|
|
|
20
|
|
|
use TYPO3\CMS\Backend\Template\ModuleTemplate; |
|
21
|
|
|
use TYPO3\CMS\Core\Messaging\FlashMessageService; |
|
22
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
23
|
|
|
use TYPO3\CMS\Extbase\Service\ExtensionService; |
|
24
|
|
|
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; |
|
25
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; |
|
26
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; |
|
27
|
|
|
use TYPO3Fluid\Fluid\View\Exception; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* A ViewHelper for having properly styled backend modules. |
|
31
|
|
|
* It is recommended to use it in Fluid Layouts. |
|
32
|
|
|
* It will render the required HTML for the doc header. |
|
33
|
|
|
* All module specific output and further configuration of the doc header |
|
34
|
|
|
* must be rendered as children of this ViewHelper. |
|
35
|
|
|
* |
|
36
|
|
|
* Examples |
|
37
|
|
|
* ======== |
|
38
|
|
|
* |
|
39
|
|
|
* Default:: |
|
40
|
|
|
* |
|
41
|
|
|
* <be:moduleLayout> |
|
42
|
|
|
* <f:render section="content" /> |
|
43
|
|
|
* </be:moduleLayout> |
|
44
|
|
|
* |
|
45
|
|
|
* Output:: |
|
46
|
|
|
* |
|
47
|
|
|
* <!-- HTML of the backend module --> |
|
48
|
|
|
*/ |
|
49
|
|
|
class ModuleLayoutViewHelper extends AbstractViewHelper |
|
50
|
|
|
{ |
|
51
|
|
|
use CompileWithRenderStatic; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var bool |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $escapeOutput = false; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Initialize arguments. |
|
60
|
|
|
* |
|
61
|
|
|
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception |
|
62
|
|
|
*/ |
|
63
|
|
|
public function initializeArguments() |
|
64
|
|
|
{ |
|
65
|
|
|
parent::initializeArguments(); |
|
66
|
|
|
$this->registerArgument('name', 'string', 'Name of the module, defaults to the current plugin name, if available', false); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public static function renderStatic( |
|
70
|
|
|
array $arguments, |
|
71
|
|
|
\Closure $renderChildrenClosure, |
|
72
|
|
|
RenderingContextInterface $renderingContext |
|
73
|
|
|
) { |
|
74
|
|
|
$viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer(); |
|
75
|
|
|
if ($viewHelperVariableContainer->exists(self::class, ModuleTemplate::class)) { |
|
76
|
|
|
throw new Exception('ModuleLayoutViewHelper can only be used once per module.', 1483292643); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$extensionService = GeneralUtility::makeInstance(ExtensionService::class); |
|
80
|
|
|
$pluginNamespace = $extensionService->getPluginNamespace( |
|
81
|
|
|
$renderingContext->getRequest()->getControllerExtensionName(), |
|
|
|
|
|
|
82
|
|
|
$renderingContext->getRequest()->getPluginName() |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
$flashMessageQueue = GeneralUtility::makeInstance(FlashMessageService::class) |
|
86
|
|
|
->getMessageQueueByIdentifier('extbase.flashmessages.' . $pluginNamespace); |
|
87
|
|
|
|
|
88
|
|
|
$moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class); |
|
89
|
|
|
$moduleTemplate->setFlashMessageQueue($flashMessageQueue); |
|
90
|
|
|
if (($arguments['name'] ?? null) !== null) { |
|
91
|
|
|
$moduleTemplate->setModuleName($arguments['name']); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$viewHelperVariableContainer->add(self::class, ModuleTemplate::class, $moduleTemplate); |
|
95
|
|
|
$moduleTemplate->setContent($renderChildrenClosure()); |
|
96
|
|
|
$viewHelperVariableContainer->remove(self::class, ModuleTemplate::class); |
|
97
|
|
|
|
|
98
|
|
|
return $moduleTemplate->renderContent(); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|