0b50d13b12c725cbe071e921038abc2ec8c712ec
[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 free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Page\PageRenderer;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
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">
35 * <f:be.container pageTitle="foo" enableClickMenu="false" loadExtJs="true" loadExtJsTheme="false" extJsAdapter="jQuery" enableExtJsDebug="true" loadJQuery="true" includeCssFiles="{0: '{f:uri.resource(path:\'Css/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>
36 * </code>
37 * <output>
38 * "your module content" wrapped with proper head & body tags.
39 * Custom CSS file EXT:your_extension/Resources/Public/Css/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 AbstractBackendViewHelper
45 {
46 /**
47 * @var bool
48 */
49 protected $escapeOutput = false;
50
51 /**
52 * Initialize arguments.
53 *
54 * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
55 */
56 public function initializeArguments()
57 {
58 parent::initializeArguments();
59 $this->registerArgument('pageTitle', 'string', 'Title tag of the module. Not required by default, as BE modules are shown in a frame', false, '');
60 $this->registerArgument('enableClickMenu', 'bool', 'If TRUE, loads clickmenu.js required by BE context menus. Defaults to TRUE', false, true);
61 $this->registerArgument('loadExtJs', 'bool', 'Specifies whether to load ExtJS library. Defaults to FALSE', false, false);
62 $this->registerArgument('loadExtJsTheme', 'bool', 'Whether to load ExtJS "grey" theme. Defaults to FALSE', false, true);
63 $this->registerArgument('enableExtJsDebug', 'bool', 'If TRUE, debug version of ExtJS is loaded. Use this for development only', false, false);
64 $this->registerArgument('loadJQuery', 'bool', 'Whether to load jQuery library. Defaults to FALSE', false, false);
65 $this->registerArgument('includeCssFiles', 'array', 'List of custom CSS file to be loaded');
66 $this->registerArgument('includeJsFiles', 'array', 'List of custom JavaScript file to be loaded');
67 $this->registerArgument('addJsInlineLabels', 'array', 'Custom labels to add to JavaScript inline labels');
68 $this->registerArgument('includeRequireJsModules', 'array', 'List of RequireJS modules to be loaded');
69 $this->registerArgument('jQueryNamespace', 'string', 'Store the jQuery object in a specific namespace');
70 }
71
72 /**
73 * Render start page with \TYPO3\CMS\Backend\Template\DocumentTemplate and pageTitle
74 *
75 * @return string
76 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
77 * @see \TYPO3\CMS\Core\Page\PageRenderer
78 */
79 public function render()
80 {
81 $pageTitle = $this->arguments['pageTitle'];
82 $enableClickMenu = $this->arguments['enableClickMenu'];
83 $loadExtJs = $this->arguments['loadExtJs'];
84 $loadExtJsTheme = $this->arguments['loadExtJsTheme'];
85 $enableExtJsDebug = $this->arguments['enableExtJsDebug'];
86 $loadJQuery = $this->arguments['loadJQuery'];
87 $includeCssFiles = $this->arguments['includeCssFiles'];
88 $includeJsFiles = $this->arguments['includeJsFiles'];
89 $addJsInlineLabels = $this->arguments['addJsInlineLabels'];
90 $includeRequireJsModules = $this->arguments['includeRequireJsModules'];
91 $jQueryNamespace = $this->arguments['jQueryNamespace'];
92
93 $pageRenderer = $this->getPageRenderer();
94 $doc = $this->getDocInstance();
95 $doc->JScode .= GeneralUtility::wrapJS($doc->redirectUrls());
96
97 // Load various standard libraries
98 if ($enableClickMenu) {
99 $pageRenderer->loadJquery();
100 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
101 }
102 if ($loadExtJs) {
103 $pageRenderer->loadExtJS(true, $loadExtJsTheme);
104 if ($enableExtJsDebug) {
105 $pageRenderer->enableExtJsDebug();
106 }
107 }
108 if ($loadJQuery) {
109 $jQueryNamespace = $jQueryNamespace ?: PageRenderer::JQUERY_NAMESPACE_DEFAULT;
110 $pageRenderer->loadJquery(null, null, $jQueryNamespace);
111 }
112 // Include custom CSS and JS files
113 if (is_array($includeCssFiles) && count($includeCssFiles) > 0) {
114 foreach ($includeCssFiles as $addCssFile) {
115 $pageRenderer->addCssFile($addCssFile);
116 }
117 }
118 if (is_array($includeJsFiles) && count($includeJsFiles) > 0) {
119 foreach ($includeJsFiles as $addJsFile) {
120 $pageRenderer->addJsFile($addJsFile);
121 }
122 }
123 if (is_array($includeRequireJsModules) && count($includeRequireJsModules) > 0) {
124 foreach ($includeRequireJsModules as $addRequireJsFile) {
125 $pageRenderer->loadRequireJsModule($addRequireJsFile);
126 }
127 }
128 // Add inline language labels
129 if (is_array($addJsInlineLabels) && count($addJsInlineLabels) > 0) {
130 $extensionKey = $this->controllerContext->getRequest()->getControllerExtensionKey();
131 foreach ($addJsInlineLabels as $key) {
132 $label = LocalizationUtility::translate($key, $extensionKey);
133 $pageRenderer->addInlineLanguageLabel($key, $label);
134 }
135 }
136 // Render the content and return it
137 $output = $this->renderChildren();
138 $output = $doc->startPage($pageTitle) . $output;
139 $output .= $doc->endPage();
140 return $output;
141 }
142 }