‪TYPO3CMS  11.5
ModuleLayoutViewHelper.php
Go to the documentation of this file.
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 
19 
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 
51 class ‪ModuleLayoutViewHelper extends AbstractViewHelper
52 {
53  use CompileWithRenderStatic;
54 
58  protected ‪$escapeOutput = false;
59 
65  public function ‪initializeArguments()
66  {
67  parent::initializeArguments();
68  $this->registerArgument('name', 'string', 'Name of the module, defaults to the current plugin name, if available', false);
69  $this->registerArgument('title', 'string', 'Title of the module.', false);
70  }
71 
72  public static function ‪renderStatic(
73  array $arguments,
74  \Closure $renderChildrenClosure,
75  RenderingContextInterface $renderingContext
76  ) {
77  trigger_error(__CLASS__ . ' will be removed in TYPO3 v12.', E_USER_DEPRECATED);
78  $viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
79  if ($viewHelperVariableContainer->exists(self::class, ModuleTemplate::class)) {
80  throw new Exception('ModuleLayoutViewHelper can only be used once per module.', 1483292643);
81  }
82 
83  $extensionService = GeneralUtility::makeInstance(ExtensionService::class);
84  $pluginNamespace = $extensionService->getPluginNamespace(
85  $renderingContext->getRequest()->getControllerExtensionName(),
86  $renderingContext->getRequest()->getPluginName()
87  );
88 
89  $flashMessageQueue = GeneralUtility::makeInstance(FlashMessageService::class)
90  ->getMessageQueueByIdentifier('extbase.flashmessages.' . $pluginNamespace);
91 
92  $moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
93  $moduleTemplate->setFlashMessageQueue($flashMessageQueue);
94  if (($arguments['name'] ?? null) !== null) {
95  $moduleTemplate->setModuleName($arguments['name']);
96  }
97  if (($arguments['title'] ?? null) !== null) {
98  $moduleTemplate->setTitle($arguments['title']);
99  }
100 
101  $viewHelperVariableContainer->add(self::class, ModuleTemplate::class, $moduleTemplate);
102  $moduleTemplate->setContent($renderChildrenClosure());
103  $viewHelperVariableContainer->remove(self::class, ModuleTemplate::class);
104 
105  return $moduleTemplate->renderContent();
106  }
107 }
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayoutViewHelper\renderStatic
‪static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: ModuleLayoutViewHelper.php:70
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Backend\ViewHelpers
Definition: ArrayBrowserViewHelper.php:18
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayoutViewHelper\initializeArguments
‪initializeArguments()
Definition: ModuleLayoutViewHelper.php:63
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayoutViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: ModuleLayoutViewHelper.php:56
‪TYPO3\CMS\Backend\ViewHelpers\ModuleLayoutViewHelper
Definition: ModuleLayoutViewHelper.php:52
‪TYPO3\CMS\Extbase\Service\ExtensionService
Definition: ExtensionService.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:27