TYPO3 CMS  TYPO3_8-7
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 
21 
38 {
42  protected $pageRenderer;
43 
48  {
49  $this->pageRenderer = $pageRenderer;
50  }
51 
57  public function initializeArguments()
58  {
59  parent::initializeArguments();
60  $this->registerArgument('pageTitle', 'string', 'title tag of the module. Not required by default, as BE modules are shown in a frame', false, '');
61  $this->registerArgument('loadExtJs', 'bool', 'specifies whether to load ExtJS library. Defaults to FALSE. This option will be removed in TYPO3 v9', false, false);
62  $this->registerArgument('loadExtJsTheme', 'bool', 'whether to load ExtJS "grey" theme. Defaults to FALSE. This option will be removed in TYPO3 v9', false, true);
63  $this->registerArgument('enableExtJsDebug', 'bool', 'if TRUE, debug version of ExtJS is loaded. Use this for development only. This option will be removed in TYPO3 v9', false, false);
64  $this->registerArgument('loadJQuery', 'bool', 'whether to load jQuery library. Defaults to FALSE. This option will be removed in TYPO3 v9', false, false);
65  $this->registerArgument('includeCssFiles', 'array', 'List of custom CSS file to be loaded');
66  $this->registerArgument('includeJsFiles', 'array', 'List of custom JavaScript file to be loaded');
67  $this->registerArgument('addJsInlineLabels', 'array', 'Custom labels to add to JavaScript inline labels');
68  $this->registerArgument('includeRequireJsModules', 'array', 'List of RequireJS modules to be loaded');
69  $this->registerArgument('jQueryNamespace', 'string', 'Store the jQuery object in a specific namespace. This option will be removed in TYPO3 v9');
70  $this->registerArgument('addInlineSettings', 'array', 'Adds Javascript Inline Setting');
71  }
72 
76  public function render()
77  {
78  $pageTitle = $this->arguments['pageTitle'];
79  $loadExtJs = $this->arguments['loadExtJs'];
80  $loadExtJsTheme = $this->arguments['loadExtJsTheme'];
81  $enableExtJsDebug = $this->arguments['enableExtJsDebug'];
82  $loadJQuery = $this->arguments['loadJQuery'];
83  $includeCssFiles = $this->arguments['includeCssFiles'];
84  $includeJsFiles = $this->arguments['includeJsFiles'];
85  $addJsInlineLabels = $this->arguments['addJsInlineLabels'];
86  $includeRequireJsModules = $this->arguments['includeRequireJsModules'];
87  $jQueryNamespace = $this->arguments['jQueryNamespace'];
88  $addInlineSettings = $this->arguments['addInlineSettings'];
89 
90  if ($pageTitle) {
91  $this->pageRenderer->setTitle($pageTitle);
92  }
93  if ($loadExtJs) {
95  'loadExtJs',
96  $this->renderingContext,
97  'Setting "loadExtJs" and "loadExtJsTheme" in PageRenderer ViewHelper is deprecated, the option will be removed in TYPO3 v9'
98  );
99  $this->pageRenderer->loadExtJS(true, $loadExtJsTheme);
100  if ($enableExtJsDebug) {
102  'enableExtJsDebug',
103  $this->renderingContext,
104  'Setting "enableExtJsDebug" in PageRenderer ViewHelper is deprecated, the option will be removed in TYPO3 v9'
105  );
106  $this->pageRenderer->enableExtJsDebug();
107  }
108  }
109  if ($loadJQuery) {
111  'loadjQuery',
112  $this->renderingContext,
113  'Setting "loadjQuery" and "jQueryNamespace" in PageRenderer ViewHelper are deprecated, the option will be removed in TYPO3 v9'
114  );
115  $jQueryNamespace = $jQueryNamespace ?: PageRenderer::JQUERY_NAMESPACE_DEFAULT;
116  $this->pageRenderer->loadJquery(null, null, $jQueryNamespace);
117  }
118  // Include custom CSS and JS files
119  if (is_array($includeCssFiles) && count($includeCssFiles) > 0) {
120  foreach ($includeCssFiles as $addCssFile) {
121  $this->pageRenderer->addCssFile($addCssFile);
122  }
123  }
124  if (is_array($includeJsFiles) && count($includeJsFiles) > 0) {
125  foreach ($includeJsFiles as $addJsFile) {
126  $this->pageRenderer->addJsFile($addJsFile);
127  }
128  }
129  if (is_array($includeRequireJsModules) && count($includeRequireJsModules) > 0) {
130  foreach ($includeRequireJsModules as $addRequireJsFile) {
131  $this->pageRenderer->loadRequireJsModule($addRequireJsFile);
132  }
133  }
134 
135  if (is_array($addInlineSettings) && count($addInlineSettings) > 0) {
136  $this->pageRenderer->addInlineSettingArray(null, $addInlineSettings);
137  }
138 
139  // Add inline language labels
140  if (is_array($addJsInlineLabels) && count($addJsInlineLabels) > 0) {
141  $extensionKey = $this->controllerContext->getRequest()->getControllerExtensionKey();
142  foreach ($addJsInlineLabels as $key) {
143  $label = LocalizationUtility::translate($key, $extensionKey);
144  $this->pageRenderer->addInlineLanguageLabel($key, $label);
145  }
146  }
147  }
148 }
static logDeprecatedViewHelperAttribute(string $property, RenderingContextInterface $renderingContext, string $additionalMessage='')
static translate($key, $extensionName=null, $arguments=null)