‪TYPO3CMS  10.4
PageRendererViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
24 
43 class ‪PageRendererViewHelper extends AbstractViewHelper
44 {
45  use CompileWithRenderStatic;
46 
52  public function ‪initializeArguments()
53  {
54  $this->registerArgument('pageTitle', 'string', 'title tag of the module. Not required by default, as BE modules are shown in a frame', false, '');
55  $this->registerArgument('includeCssFiles', 'array', 'List of custom CSS file to be loaded');
56  $this->registerArgument('includeJsFiles', 'array', 'List of custom JavaScript file to be loaded');
57  $this->registerArgument('addJsInlineLabels', 'array', 'Custom labels to add to JavaScript inline labels');
58  $this->registerArgument('includeRequireJsModules', 'array', 'List of RequireJS modules to be loaded');
59  $this->registerArgument('addInlineSettings', 'array', 'Adds Javascript Inline Setting');
60  }
61 
67  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
68  {
69  $pageRenderer = static::getPageRenderer();
70  $pageTitle = $arguments['pageTitle'];
71  $includeCssFiles = $arguments['includeCssFiles'];
72  $includeJsFiles = $arguments['includeJsFiles'];
73  $addJsInlineLabels = $arguments['addJsInlineLabels'];
74  $includeRequireJsModules = $arguments['includeRequireJsModules'];
75  $addInlineSettings = $arguments['addInlineSettings'];
76 
77  if ($pageTitle) {
78  $pageRenderer->setTitle($pageTitle);
79  }
80 
81  // Include custom CSS and JS files
82  if (is_array($includeCssFiles) && count($includeCssFiles) > 0) {
83  foreach ($includeCssFiles as $addCssFile) {
84  $pageRenderer->addCssFile($addCssFile);
85  }
86  }
87  if (is_array($includeJsFiles) && count($includeJsFiles) > 0) {
88  foreach ($includeJsFiles as $addJsFile) {
89  $pageRenderer->addJsFile($addJsFile);
90  }
91  }
92  if (is_array($includeRequireJsModules) && count($includeRequireJsModules) > 0) {
93  foreach ($includeRequireJsModules as $addRequireJsFile) {
94  $pageRenderer->loadRequireJsModule($addRequireJsFile);
95  }
96  }
97 
98  if (is_array($addInlineSettings) && count($addInlineSettings) > 0) {
99  $pageRenderer->addInlineSettingArray(null, $addInlineSettings);
100  }
101 
102  // Add inline language labels
103  if (is_array($addJsInlineLabels) && count($addJsInlineLabels) > 0) {
104  $extensionKey = $renderingContext->getControllerContext()->getRequest()->getControllerExtensionKey();
105  foreach ($addJsInlineLabels as $key) {
106  $label = ‪LocalizationUtility::translate($key, $extensionKey);
107  $pageRenderer->addInlineLanguageLabel($key, $label);
108  }
109  }
110  }
111 
115  protected static function ‪getPageRenderer()
116  {
117  return GeneralUtility::makeInstance(PageRenderer::class);
118  }
119 }
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:33
‪TYPO3\CMS\Fluid\ViewHelpers\Be\PageRendererViewHelper
Definition: PageRendererViewHelper.php:44
‪TYPO3\CMS\Fluid\ViewHelpers\Be
Definition: AbstractBackendViewHelper.php:16
‪TYPO3\CMS\Fluid\ViewHelpers\Be\PageRendererViewHelper\getPageRenderer
‪static PageRenderer getPageRenderer()
Definition: PageRendererViewHelper.php:114
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:42
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate(string $key, ?string $extensionName=null, array $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:67
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Fluid\ViewHelpers\Be\PageRendererViewHelper\renderStatic
‪static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: PageRendererViewHelper.php:66
‪TYPO3\CMS\Fluid\ViewHelpers\Be\PageRendererViewHelper\initializeArguments
‪initializeArguments()
Definition: PageRendererViewHelper.php:51