[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 file is part of the TYPO3 CMS project.
6 *
7 * It is backported from the TYPO3 Flow package "TYPO3.Fluid".
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use \TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * View helper which allows you to create extbase based modules in the style of TYPO3 default modules.
23 *
24 * = Examples =
25 *
26 * <code title="Simple">
27 * <f:be.container>your module content</f:be.container>
28 * </code>
29 * <output>
30 * "your module content" wrapped with proper head & body tags.
31 * Default backend CSS styles and JavaScript will be included
32 * </output>
33 *
34 * <code title="All options (except deprecated ones)">
35 * <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>
36 * </code>
37 * <output>
38 * "your module content" wrapped with proper head & body tags.
39 * Custom CSS file EXT:your_extension/Resources/Public/Styles/styles.css and
40 * JavaScript files EXT:your_extension/Resources/Public/JavaScript/Library1.js and EXT:your_extension/Resources/Public/JavaScript/Library2.js
41 * will be loaded, plus ExtJS and jQuery and some inline labels for usage in JS code.
42 * </output>
43 */
44 class ContainerViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper {
45
46 /**
47 * Render start page with \TYPO3\CMS\Backend\Template\DocumentTemplate and pageTitle
48 *
49 * @param string $pageTitle title tag of the module. Not required by default, as BE modules are shown in a frame
50 * @param boolean $enableJumpToUrl If TRUE, includes "jumpTpUrl" javascript function required by ActionMenu. Defaults to TRUE, deprecated, as not needed anymore
51 * @param boolean $enableClickMenu If TRUE, loads clickmenu.js required by BE context menus. Defaults to TRUE
52 * @param boolean $loadPrototype specifies whether to load prototype library. Defaults to TRUE
53 * @param boolean $loadScriptaculous specifies whether to load scriptaculous libraries. Defaults to FALSE
54 * @param string $scriptaculousModule additionales modules for scriptaculous
55 * @param boolean $loadExtJs specifies whether to load ExtJS library. Defaults to FALSE
56 * @param boolean $loadExtJsTheme whether to load ExtJS "grey" theme. Defaults to FALSE
57 * @param string $extJsAdapter load alternative adapter (ext-base is default adapter)
58 * @param boolean $enableExtJsDebug if TRUE, debug version of ExtJS is loaded. Use this for development only
59 * @param string $addCssFile Custom CSS file to be loaded (deprecated, use $includeCssFiles)
60 * @param string $addJsFile Custom JavaScript file to be loaded (deprecated, use $includeJsFiles)
61 * @param boolean $loadJQuery whether to load jQuery library. Defaults to FALSE
62 * @param array $includeCssFiles List of custom CSS file to be loaded
63 * @param array $includeJsFiles List of custom JavaScript file to be loaded
64 * @param array $addJsInlineLabels Custom labels to add to JavaScript inline labels
65 * @param boolean $includeCsh flag for including CSH
66 * @return string
67 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
68 * @see \TYPO3\CMS\Core\Page\PageRenderer
69 */
70 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) {
71 $doc = $this->getDocInstance();
72 $pageRenderer = $doc->getPageRenderer();
73 $doc->JScode .= $doc->wrapScriptTags($doc->redirectUrls());
74
75 // Load various standard libraries
76 if ($enableClickMenu) {
77 $doc->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/clickmenu.js');
78 }
79 if ($loadPrototype) {
80 $pageRenderer->loadPrototype();
81 }
82 if ($loadScriptaculous) {
83 $pageRenderer->loadScriptaculous($scriptaculousModule);
84 }
85 if ($loadExtJs) {
86 $pageRenderer->loadExtJS(TRUE, $loadExtJsTheme, $extJsAdapter);
87 if ($enableExtJsDebug) {
88 $pageRenderer->enableExtJsDebug();
89 }
90 }
91 if ($loadJQuery) {
92 $pageRenderer->loadJquery(NULL, NULL, $pageRenderer::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT);
93 }
94 // This way of adding a single CSS or JS file is deprecated, the array below should be used instead
95 if ($addCssFile !== NULL) {
96 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.');
97 $pageRenderer->addCssFile($addCssFile);
98 }
99 if ($addJsFile !== NULL) {
100 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.');
101 $pageRenderer->addJsFile($addJsFile);
102 }
103 // Include custom CSS and JS files
104 if (is_array($includeCssFiles) && count($includeCssFiles) > 0) {
105 foreach ($includeCssFiles as $addCssFile) {
106 $pageRenderer->addCssFile($addCssFile);
107 }
108 }
109 if (is_array($includeJsFiles) && count($includeJsFiles) > 0) {
110 foreach ($includeJsFiles as $addJsFile) {
111 $pageRenderer->addJsFile($addJsFile);
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 = \TYPO3\CMS\Extbase\Utility\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 }