bd550badc0e12ac6fd26b41be34c9e81c7216603
[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 script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23
24 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
25
26
27 /**
28 * View helper which allows you to create extbase based modules in the style of TYPO3 default modules.
29 *
30 * = Examples =
31 *
32 * <code title="Simple">
33 * <f:be.container>your module content</f:be.container>
34 * </code>
35 * <output>
36 * "your module content" wrapped with proper head & body tags.
37 * Default backend CSS styles and JavaScript will be included
38 * </output>
39 *
40 * <code title="All options">
41 * <f:be.container pageTitle="foo" enableClickMenu="false" loadPrototype="false" loadScriptaculous="false" scriptaculousModule="someModule,someOtherModule" loadExtJs="true" loadExtJsTheme="false" extJsAdapter="jQuery" enableExtJsDebug="true" loadJQuery="true" includeCssFiles="0: '{f:uri.resource(path:\'Styles/Styles.css\')}'" includeJsFiles="0: '{f:uri.resource(path:\'JavaScript/Library1.js\')}', 1: '{f:uri.resource(path:\'JavaScript/Library2.js\')}'" addJsInlineLabels="{0: 'label1', 1: 'label2'}" includeCsh="true">your module content</f:be.container>
42 * </code>
43 * <output>
44 * "your module content" wrapped with proper head & body tags.
45 * Custom CSS file EXT:your_extension/Resources/Public/Styles/styles.css and
46 * JavaScript files EXT:your_extension/Resources/Public/JavaScript/Library1.js and EXT:your_extension/Resources/Public/JavaScript/Library2.js
47 * will be loaded, plus ExtJS and jQuery and some inline labels for usage in JS code.
48 * </output>
49 */
50 class ContainerViewHelper extends AbstractBackendViewHelper {
51
52 /**
53 * Render start page with \TYPO3\CMS\Backend\Template\DocumentTemplate and pageTitle
54 *
55 * @param string $pageTitle title tag of the module. Not required by default, as BE modules are shown in a frame
56 * @param bool $enableClickMenu If TRUE, loads clickmenu.js required by BE context menus. Defaults to TRUE
57 * @param bool $loadPrototype specifies whether to load prototype library. Defaults to TRUE
58 * @param bool $loadScriptaculous specifies whether to load scriptaculous libraries. Defaults to FALSE
59 * @param string $scriptaculousModule additionales modules for scriptaculous
60 * @param bool $loadExtJs specifies whether to load ExtJS library. Defaults to FALSE
61 * @param bool $loadExtJsTheme whether to load ExtJS "grey" theme. Defaults to FALSE
62 * @param bool $enableExtJsDebug if TRUE, debug version of ExtJS is loaded. Use this for development only
63 * @param bool $loadJQuery whether to load jQuery library. Defaults to FALSE
64 * @param array $includeCssFiles List of custom CSS file to be loaded
65 * @param array $includeJsFiles List of custom JavaScript file to be loaded
66 * @param array $addJsInlineLabels Custom labels to add to JavaScript inline labels
67 * @param bool $includeCsh flag for including CSH
68 * @param array $includeRequireJsModules List of RequireJS modules to be loaded
69 * @return string
70 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
71 * @see \TYPO3\CMS\Core\Page\PageRenderer
72 */
73 public function render($pageTitle = '', $enableClickMenu = TRUE, $loadPrototype = TRUE, $loadScriptaculous = FALSE, $scriptaculousModule = '', $loadExtJs = FALSE, $loadExtJsTheme = TRUE, $enableExtJsDebug = FALSE, $loadJQuery = FALSE, $includeCssFiles = NULL, $includeJsFiles = NULL, $addJsInlineLabels = NULL, $includeCsh = TRUE, $includeRequireJsModules = NULL) {
74 $pageRenderer = $this->getPageRenderer();
75 $doc = $this->getDocInstance();
76 $doc->JScode .= $doc->wrapScriptTags($doc->redirectUrls());
77
78 // Load various standard libraries
79 if ($enableClickMenu) {
80 $doc->getContextMenuCode();
81 }
82 if ($loadPrototype) {
83 $pageRenderer->loadPrototype();
84 }
85 if ($loadScriptaculous) {
86 $pageRenderer->loadScriptaculous($scriptaculousModule);
87 }
88 if ($loadExtJs) {
89 $pageRenderer->loadExtJS(TRUE, $loadExtJsTheme);
90 if ($enableExtJsDebug) {
91 $pageRenderer->enableExtJsDebug();
92 }
93 }
94 if ($loadJQuery) {
95 $pageRenderer->loadJquery(NULL, NULL, $pageRenderer::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT);
96 }
97 // Include custom CSS and JS files
98 if (is_array($includeCssFiles) && count($includeCssFiles) > 0) {
99 foreach ($includeCssFiles as $addCssFile) {
100 $pageRenderer->addCssFile($addCssFile);
101 }
102 }
103 if (is_array($includeJsFiles) && count($includeJsFiles) > 0) {
104 foreach ($includeJsFiles as $addJsFile) {
105 $pageRenderer->addJsFile($addJsFile);
106 }
107 }
108 if (is_array($includeRequireJsModules) && count($includeRequireJsModules) > 0) {
109 foreach ($includeRequireJsModules as $addRequireJsFile) {
110 $pageRenderer->loadRequireJsModule($addRequireJsFile);
111 }
112 }
113 // Add inline language labels
114 if (is_array($addJsInlineLabels) && count($addJsInlineLabels) > 0) {
115 $extensionKey = $this->controllerContext->getRequest()->getControllerExtensionKey();
116 foreach ($addJsInlineLabels as $key) {
117 $label = LocalizationUtility::translate($key, $extensionKey);
118 $pageRenderer->addInlineLanguageLabel($key, $label);
119 }
120 }
121 // Render the content and return it
122 $output = $this->renderChildren();
123 $output = $doc->startPage($pageTitle, $includeCsh) . $output;
124 $output .= $doc->endPage();
125 return $output;
126 }
127
128 }