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