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