Revert "[CLEANUP] Rework/simplify copyright header and remove @package"
[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'}" includeCsh="true">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 * @param boolean $includeCsh flag for including CSH
71 * @return string
72 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
73 * @see \TYPO3\CMS\Core\Page\PageRenderer
74 */
75 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, $includeCsh = TRUE) {
76 $doc = $this->getDocInstance();
77 $pageRenderer = $doc->getPageRenderer();
78 $doc->JScode .= $doc->wrapScriptTags($doc->redirectUrls());
79
80 // Load various standard libraries
81 if ($enableClickMenu) {
82 $doc->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/clickmenu.js');
83 }
84 if ($loadPrototype) {
85 $pageRenderer->loadPrototype();
86 }
87 if ($loadScriptaculous) {
88 $pageRenderer->loadScriptaculous($scriptaculousModule);
89 }
90 if ($loadExtJs) {
91 $pageRenderer->loadExtJS(TRUE, $loadExtJsTheme, $extJsAdapter);
92 if ($enableExtJsDebug) {
93 $pageRenderer->enableExtJsDebug();
94 }
95 }
96 if ($loadJQuery) {
97 $pageRenderer->loadJquery(NULL, NULL, $pageRenderer::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT);
98 }
99 // This way of adding a single CSS or JS file is deprecated, the array below should be used instead
100 if ($addCssFile !== NULL) {
101 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.');
102 $pageRenderer->addCssFile($addCssFile);
103 }
104 if ($addJsFile !== NULL) {
105 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.');
106 $pageRenderer->addJsFile($addJsFile);
107 }
108 // Include custom CSS and JS files
109 if (is_array($includeCssFiles) && count($includeCssFiles) > 0) {
110 foreach ($includeCssFiles as $addCssFile) {
111 $pageRenderer->addCssFile($addCssFile);
112 }
113 }
114 if (is_array($includeJsFiles) && count($includeJsFiles) > 0) {
115 foreach ($includeJsFiles as $addJsFile) {
116 $pageRenderer->addJsFile($addJsFile);
117 }
118 }
119 // Add inline language labels
120 if (is_array($addJsInlineLabels) && count($addJsInlineLabels) > 0) {
121 $extensionKey = $this->controllerContext->getRequest()->getControllerExtensionKey();
122 foreach ($addJsInlineLabels as $key) {
123 $label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, $extensionKey);
124 $pageRenderer->addInlineLanguageLabel($key, $label);
125 }
126 }
127 // Render the content and return it
128 $output = $this->renderChildren();
129 $output = $doc->startPage($pageTitle, $includeCsh) . $output;
130 $output .= $doc->endPage();
131 return $output;
132 }
133 }