[FEATURE] Allow ContainerViewHelper to load RequireJS modules
[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 string $extJsAdapter load alternative adapter (ext-base is default adapter)
63 * @param bool $enableExtJsDebug if TRUE, debug version of ExtJS is loaded. Use this for development only
64 * @param bool $loadJQuery whether to load jQuery library. Defaults to FALSE
65 * @param array $includeCssFiles List of custom CSS file to be loaded
66 * @param array $includeJsFiles List of custom JavaScript file to be loaded
67 * @param array $addJsInlineLabels Custom labels to add to JavaScript inline labels
68 * @param bool $includeCsh flag for including CSH
69 * @param array $includeRequireJsModules List of RequireJS modules to be loaded
70 * @return string
71 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
72 * @see \TYPO3\CMS\Core\Page\PageRenderer
73 */
74 public function render($pageTitle = '', $enableClickMenu = TRUE, $loadPrototype = TRUE, $loadScriptaculous = FALSE, $scriptaculousModule = '', $loadExtJs = FALSE, $loadExtJsTheme = TRUE, $extJsAdapter = '', $enableExtJsDebug = FALSE, $loadJQuery = FALSE, $includeCssFiles = NULL, $includeJsFiles = NULL, $addJsInlineLabels = NULL, $includeCsh = TRUE, $includeRequireJsModules = NULL) {
75 $doc = $this->getDocInstance();
76 $pageRenderer = $doc->getPageRenderer();
77 $doc->JScode .= $doc->wrapScriptTags($doc->redirectUrls());
78
79 // Load various standard libraries
80 if ($enableClickMenu) {
81 $doc->getContextMenuCode();
82 }
83 if ($loadPrototype) {
84 $pageRenderer->loadPrototype();
85 }
86 if ($loadScriptaculous) {
87 $pageRenderer->loadScriptaculous($scriptaculousModule);
88 }
89 if ($loadExtJs) {
90 $pageRenderer->loadExtJS(TRUE, $loadExtJsTheme, $extJsAdapter);
91 if ($enableExtJsDebug) {
92 $pageRenderer->enableExtJsDebug();
93 }
94 }
95 if ($loadJQuery) {
96 $pageRenderer->loadJquery(NULL, NULL, $pageRenderer::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT);
97 }
98 // Include custom CSS and JS files
99 if (is_array($includeCssFiles) && count($includeCssFiles) > 0) {
100 foreach ($includeCssFiles as $addCssFile) {
101 $pageRenderer->addCssFile($addCssFile);
102 }
103 }
104 if (is_array($includeJsFiles) && count($includeJsFiles) > 0) {
105 foreach ($includeJsFiles as $addJsFile) {
106 $pageRenderer->addJsFile($addJsFile);
107 }
108 }
109 if (is_array($includeRequireJsModules) && count($includeRequireJsModules) > 0) {
110 foreach ($includeRequireJsModules as $addRequireJsFile) {
111 $pageRenderer->loadRequireJsModule($addRequireJsFile);
112 }
113 }
114 // Add inline language labels
115 if (is_array($addJsInlineLabels) && count($addJsInlineLabels) > 0) {
116 $extensionKey = $this->controllerContext->getRequest()->getControllerExtensionKey();
117 foreach ($addJsInlineLabels as $key) {
118 $label = LocalizationUtility::translate($key, $extensionKey);
119 $pageRenderer->addInlineLanguageLabel($key, $label);
120 }
121 }
122 // Render the content and return it
123 $output = $this->renderChildren();
124 $output = $doc->startPage($pageTitle, $includeCsh) . $output;
125 $output .= $doc->endPage();
126 return $output;
127 }
128
129 }