[CLEANUP] Cleanup jumpToUrl() and unused JS in Backend
[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\Core\Utility\GeneralUtility;
25
26 /**
27 * View helper which allows you to create extbase based modules in the style of TYPO3 default modules.
28 *
29 * = Examples =
30 *
31 * <code title="Simple">
32 * <f:be.container>your module content</f:be.container>
33 * </code>
34 * <output>
35 * "your module content" wrapped with proper head & body tags.
36 * Default backend CSS styles and JavaScript will be included
37 * </output>
38 *
39 * <code title="All options (except deprecated ones)">
40 * <f:be.container pageTitle="foo" enableJumpToUrl="false" 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'}">your module content</f:be.container>
41 * </code>
42 * <output>
43 * "your module content" wrapped with proper head & body tags.
44 * Custom CSS file EXT:your_extension/Resources/Public/Styles/styles.css and
45 * JavaScript files EXT:your_extension/Resources/Public/JavaScript/Library1.js and EXT:your_extension/Resources/Public/JavaScript/Library2.js
46 * will be loaded, plus ExtJS and jQuery and some inline labels for usage in JS code.
47 * </output>
48 */
49 class ContainerViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper {
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 boolean $enableJumpToUrl If TRUE, includes "jumpTpUrl" javascript function required by ActionMenu. Defaults to TRUE, deprecated, as not needed anymore
56 * @param boolean $enableClickMenu If TRUE, loads clickmenu.js required by BE context menus. Defaults to TRUE
57 * @param boolean $loadPrototype specifies whether to load prototype library. Defaults to TRUE
58 * @param boolean $loadScriptaculous specifies whether to load scriptaculous libraries. Defaults to FALSE
59 * @param string $scriptaculousModule additionales modules for scriptaculous
60 * @param boolean $loadExtJs specifies whether to load ExtJS library. Defaults to FALSE
61 * @param boolean $loadExtJsTheme whether to load ExtJS "grey" theme. Defaults to FALSE
62 * @param string $extJsAdapter load alternative adapter (ext-base is default adapter)
63 * @param boolean $enableExtJsDebug if TRUE, debug version of ExtJS is loaded. Use this for development only
64 * @param string $addCssFile Custom CSS file to be loaded (deprecated, use $includeCssFiles)
65 * @param string $addJsFile Custom JavaScript file to be loaded (deprecated, use $includeJsFiles)
66 * @param boolean $loadJQuery whether to load jQuery library. Defaults to FALSE
67 * @param array $includeCssFiles List of custom CSS file to be loaded
68 * @param array $includeJsFiles List of custom JavaScript file to be loaded
69 * @param array $addJsInlineLabels Custom labels to add to JavaScript inline labels
70 * @return string
71 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
72 * @see \TYPO3\CMS\Core\Page\PageRenderer
73 */
74 public function render($pageTitle = '', $enableJumpToUrl = TRUE, $enableClickMenu = TRUE, $loadPrototype = TRUE, $loadScriptaculous = FALSE, $scriptaculousModule = '', $loadExtJs = FALSE, $loadExtJsTheme = TRUE, $extJsAdapter = '', $enableExtJsDebug = FALSE, $addCssFile = NULL, $addJsFile = NULL, $loadJQuery = FALSE, $includeCssFiles = NULL, $includeJsFiles = NULL, $addJsInlineLabels = 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->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/clickmenu.js');
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 // This way of adding a single CSS or JS file is deprecated, the array below should be used instead
99 if ($addCssFile !== NULL) {
100 GeneralUtility::deprecationLog('Usage of addCssFile attribute is deprecated since TYPO3 CMS 6.2. It will be removed in TYPO3 CMS 7.0. Use includeCssFiles instead.');
101 $pageRenderer->addCssFile($addCssFile);
102 }
103 if ($addJsFile !== NULL) {
104 GeneralUtility::deprecationLog('Usage of addJsFile attribute is deprecated since TYPO3 CMS 6.2. It will be removed in TYPO3 CMS 7.0. Use includeJsFiles instead.');
105 $pageRenderer->addJsFile($addJsFile);
106 }
107 // Include custom CSS and JS files
108 if (is_array($includeCssFiles) && count($includeCssFiles) > 0) {
109 foreach ($includeCssFiles as $addCssFile) {
110 $pageRenderer->addCssFile($addCssFile);
111 }
112 }
113 if (is_array($includeJsFiles) && count($includeJsFiles) > 0) {
114 foreach ($includeJsFiles as $addJsFile) {
115 $pageRenderer->addJsFile($addJsFile);
116 }
117 }
118 // Add inline language labels
119 if (is_array($addJsInlineLabels) && count($addJsInlineLabels) > 0) {
120 $extensionKey = $this->controllerContext->getRequest()->getControllerExtensionKey();
121 foreach ($addJsInlineLabels as $key) {
122 $label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, $extensionKey);
123 $pageRenderer->addInlineLanguageLabel($key, $label);
124 }
125 }
126 // Render the content and return it
127 $output = $this->renderChildren();
128 $output = $doc->startPage($pageTitle) . $output;
129 $output .= $doc->endPage();
130 return $output;
131 }
132 }