TYPO3 CMS  TYPO3_8-7
ContainerViewHelper.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 
45 {
49  protected $escapeOutput = false;
50 
56  public function initializeArguments()
57  {
58  parent::initializeArguments();
59  $this->registerArgument('pageTitle', 'string', 'Title tag of the module. Not required by default, as BE modules are shown in a frame', false, '');
60  $this->registerArgument('enableClickMenu', 'bool', 'If TRUE, loads clickmenu.js required by BE context menus. Defaults to TRUE. This option will be removed in TYPO3 v9', false, true);
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  }
71 
79  public function render()
80  {
81  $pageTitle = $this->arguments['pageTitle'];
82  $enableClickMenu = $this->arguments['enableClickMenu'];
83  $loadExtJs = $this->arguments['loadExtJs'];
84  $loadExtJsTheme = $this->arguments['loadExtJsTheme'];
85  $enableExtJsDebug = $this->arguments['enableExtJsDebug'];
86  $loadJQuery = $this->arguments['loadJQuery'];
87  $includeCssFiles = $this->arguments['includeCssFiles'];
88  $includeJsFiles = $this->arguments['includeJsFiles'];
89  $addJsInlineLabels = $this->arguments['addJsInlineLabels'];
90  $includeRequireJsModules = $this->arguments['includeRequireJsModules'];
91  $jQueryNamespace = $this->arguments['jQueryNamespace'];
92 
93  $pageRenderer = $this->getPageRenderer();
94  $doc = $this->getDocInstance();
95  $doc->JScode .= GeneralUtility::wrapJS($doc->redirectUrls());
96 
97  // Load various standard libraries
98  if ($enableClickMenu) {
100  'enableClickMenu',
101  $this->renderingContext,
102  'Setting "enableClickMenu" in Container ViewHelper is deprecated, the option will be removed in TYPO3 v9'
103  );
104  $pageRenderer->loadJquery();
105  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
106  }
107  if ($loadExtJs) {
109  'loadExtJs',
110  $this->renderingContext,
111  'Setting "loadExtJs" and "loadExtJsTheme" in Container ViewHelper is deprecated, the option will be removed in TYPO3 v9'
112  );
113  $pageRenderer->loadExtJS(true, $loadExtJsTheme);
114  if ($enableExtJsDebug) {
116  'enableExtJsDebug',
117  $this->renderingContext,
118  'Setting "enableExtJsDebug" in Container ViewHelper is deprecated, the option will be removed in TYPO3 v9'
119  );
120  $pageRenderer->enableExtJsDebug();
121  }
122  }
123  if ($loadJQuery) {
125  'loadjQuery',
126  $this->renderingContext,
127  'Setting "loadjQuery" and "jQueryNamespace" in Container ViewHelper are deprecated, the option will be removed in TYPO3 v9'
128  );
129  $jQueryNamespace = $jQueryNamespace ?: PageRenderer::JQUERY_NAMESPACE_DEFAULT;
130  $pageRenderer->loadJquery(null, null, $jQueryNamespace);
131  }
132  // Include custom CSS and JS files
133  if (is_array($includeCssFiles) && count($includeCssFiles) > 0) {
134  foreach ($includeCssFiles as $addCssFile) {
135  $pageRenderer->addCssFile($addCssFile);
136  }
137  }
138  if (is_array($includeJsFiles) && count($includeJsFiles) > 0) {
139  foreach ($includeJsFiles as $addJsFile) {
140  $pageRenderer->addJsFile($addJsFile);
141  }
142  }
143  if (is_array($includeRequireJsModules) && count($includeRequireJsModules) > 0) {
144  foreach ($includeRequireJsModules as $addRequireJsFile) {
145  $pageRenderer->loadRequireJsModule($addRequireJsFile);
146  }
147  }
148  // Add inline language labels
149  if (is_array($addJsInlineLabels) && count($addJsInlineLabels) > 0) {
150  $extensionKey = $this->controllerContext->getRequest()->getControllerExtensionKey();
151  foreach ($addJsInlineLabels as $key) {
152  $label = LocalizationUtility::translate($key, $extensionKey);
153  $pageRenderer->addInlineLanguageLabel($key, $label);
154  }
155  }
156  // Render the content and return it
157  $output = $this->renderChildren();
158  $output = $doc->startPage($pageTitle) . $output;
159  $output .= $doc->endPage();
160  return $output;
161  }
162 }
static logDeprecatedViewHelperAttribute(string $property, RenderingContextInterface $renderingContext, string $additionalMessage='')
static translate($key, $extensionName=null, $arguments=null)