[TASK] Deprecate DocumentTemplate methods
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / ContainerViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be;
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
17 use TYPO3\CMS\Core\Page\PageRenderer;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
20
21 /**
22 * View helper which allows you to create extbase based modules in the style of TYPO3 default modules.
23 *
24 * = Examples =
25 *
26 * <code title="Simple">
27 * <f:be.container>your module content</f:be.container>
28 * </code>
29 * <output>
30 * "your module content" wrapped with proper head & body tags.
31 * Default backend CSS styles and JavaScript will be included
32 * </output>
33 *
34 * <code title="All options">
35 * <f:be.container pageTitle="foo" enableClickMenu="false" loadExtJs="true" loadExtJsTheme="false" extJsAdapter="jQuery" enableExtJsDebug="true" loadJQuery="true" includeCssFiles="{0: '{f:uri.resource(path:\'Css/Styles.css\')}'}" includeJsFiles="{0: '{f:uri.resource(path:\'JavaScript/Library1.js\')}', 1: '{f:uri.resource(path:\'JavaScript/Library2.js\')}'}" addJsInlineLabels="{0: 'label1', 1: 'label2'}">your module content</f:be.container>
36 * </code>
37 * <output>
38 * "your module content" wrapped with proper head & body tags.
39 * Custom CSS file EXT:your_extension/Resources/Public/Css/styles.css and
40 * JavaScript files EXT:your_extension/Resources/Public/JavaScript/Library1.js and EXT:your_extension/Resources/Public/JavaScript/Library2.js
41 * will be loaded, plus ExtJS and jQuery and some inline labels for usage in JS code.
42 * </output>
43 */
44 class ContainerViewHelper extends AbstractBackendViewHelper
45 {
46 /**
47 * @var bool
48 */
49 protected $escapeOutput = false;
50
51 /**
52 * Render start page with \TYPO3\CMS\Backend\Template\DocumentTemplate and pageTitle
53 *
54 * @param string $pageTitle title tag of the module. Not required by default, as BE modules are shown in a frame
55 * @param bool $enableClickMenu If TRUE, loads clickmenu.js required by BE context menus. Defaults to TRUE
56 * @param bool $loadExtJs specifies whether to load ExtJS library. Defaults to FALSE
57 * @param bool $loadExtJsTheme whether to load ExtJS "grey" theme. Defaults to FALSE
58 * @param bool $enableExtJsDebug if TRUE, debug version of ExtJS is loaded. Use this for development only
59 * @param bool $loadJQuery whether to load jQuery library. Defaults to FALSE
60 * @param array $includeCssFiles List of custom CSS file to be loaded
61 * @param array $includeJsFiles List of custom JavaScript file to be loaded
62 * @param array $addJsInlineLabels Custom labels to add to JavaScript inline labels
63 * @param array $includeRequireJsModules List of RequireJS modules to be loaded
64 * @param string $jQueryNamespace Store the jQuery object in a specific namespace
65 * @return string
66 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
67 * @see \TYPO3\CMS\Core\Page\PageRenderer
68 */
69 public function render($pageTitle = '', $enableClickMenu = true, $loadExtJs = false, $loadExtJsTheme = true, $enableExtJsDebug = false, $loadJQuery = false, $includeCssFiles = null, $includeJsFiles = null, $addJsInlineLabels = null, $includeRequireJsModules = null, $jQueryNamespace = null)
70 {
71 $pageRenderer = $this->getPageRenderer();
72 $doc = $this->getDocInstance();
73 $doc->JScode .= GeneralUtility::wrapJS($doc->redirectUrls());
74
75 // Load various standard libraries
76 if ($enableClickMenu) {
77 $pageRenderer->loadJquery();
78 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
79 }
80 if ($loadExtJs) {
81 $pageRenderer->loadExtJS(true, $loadExtJsTheme);
82 if ($enableExtJsDebug) {
83 $pageRenderer->enableExtJsDebug();
84 }
85 }
86 if ($loadJQuery) {
87 $jQueryNamespace = $jQueryNamespace ?: PageRenderer::JQUERY_NAMESPACE_DEFAULT;
88 $pageRenderer->loadJquery(null, null, $jQueryNamespace);
89 }
90 // Include custom CSS and JS files
91 if (is_array($includeCssFiles) && count($includeCssFiles) > 0) {
92 foreach ($includeCssFiles as $addCssFile) {
93 $pageRenderer->addCssFile($addCssFile);
94 }
95 }
96 if (is_array($includeJsFiles) && count($includeJsFiles) > 0) {
97 foreach ($includeJsFiles as $addJsFile) {
98 $pageRenderer->addJsFile($addJsFile);
99 }
100 }
101 if (is_array($includeRequireJsModules) && count($includeRequireJsModules) > 0) {
102 foreach ($includeRequireJsModules as $addRequireJsFile) {
103 $pageRenderer->loadRequireJsModule($addRequireJsFile);
104 }
105 }
106 // Add inline language labels
107 if (is_array($addJsInlineLabels) && count($addJsInlineLabels) > 0) {
108 $extensionKey = $this->controllerContext->getRequest()->getControllerExtensionKey();
109 foreach ($addJsInlineLabels as $key) {
110 $label = LocalizationUtility::translate($key, $extensionKey);
111 $pageRenderer->addInlineLanguageLabel($key, $label);
112 }
113 }
114 // Render the content and return it
115 $output = $this->renderChildren();
116 $output = $doc->startPage($pageTitle) . $output;
117 $output .= $doc->endPage();
118 return $output;
119 }
120 }