[BUGFIX] Fix several typos in php comments
[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\Utility\GeneralUtility;
18 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
19
20 /**
21 * ViewHelper which allows you to create extbase based modules in the style of TYPO3 default modules.
22 *
23 * Examples
24 * ========
25 *
26 * Simple::
27 *
28 * <f:be.container>your module content</f:be.container>
29 *
30 * "your module content" wrapped with proper head & body tags.
31 * Default backend CSS styles and JavaScript will be included.
32 *
33 * All options::
34 *
35 * <f:be.container pageTitle="foo"
36 * includeCssFiles="{0: '{f:uri.resource(path:\'Css/Styles.css\')}'}"
37 * includeJsFiles="{0: '{f:uri.resource(path:\'JavaScript/Library1.js\')}', 1: '{f:uri.resource(path:\'JavaScript/Library2.js\')}'}"
38 * addJsInlineLabels="{0: 'label1', 1: 'label2'}"
39 * >
40 * your module content
41 * </f:be.container>
42 *
43 * "your module content" wrapped with proper head & body tags.
44 * Custom CSS file :file:`EXT:your_extension/Resources/Public/Css/styles.css` and
45 * JavaScript files :file:`EXT:your_extension/Resources/Public/JavaScript/Library1.js` and
46 * :file:`EXT:your_extension/Resources/Public/JavaScript/Library2.js`
47 * will be loaded, plus some inline labels for usage in JS code.
48 */
49 class ContainerViewHelper extends AbstractBackendViewHelper
50 {
51 /**
52 * @var bool
53 */
54 protected $escapeOutput = false;
55
56 /**
57 * Initialize arguments.
58 *
59 * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
60 */
61 public function initializeArguments()
62 {
63 parent::initializeArguments();
64 $this->registerArgument('pageTitle', 'string', 'Title tag of the module. Not required by default, as BE modules are shown in a frame', 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 }
70
71 /**
72 * Render start page with \TYPO3\CMS\Backend\Template\DocumentTemplate and pageTitle
73 *
74 * @return string
75 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
76 * @see \TYPO3\CMS\Core\Page\PageRenderer
77 */
78 public function render()
79 {
80 $pageTitle = $this->arguments['pageTitle'];
81 $includeCssFiles = $this->arguments['includeCssFiles'];
82 $includeJsFiles = $this->arguments['includeJsFiles'];
83 $addJsInlineLabels = $this->arguments['addJsInlineLabels'];
84 $includeRequireJsModules = $this->arguments['includeRequireJsModules'];
85
86 $pageRenderer = $this->getPageRenderer();
87 $doc = $this->getDocInstance();
88 $doc->JScode .= GeneralUtility::wrapJS($doc->redirectUrls());
89
90 // Include custom CSS and JS files
91 if (is_array($includeCssFiles) && count($includeCssFiles) > 0) {
92 foreach ($includeCssFiles as $addCssFile) {
93 $pageRenderer->addCssFile($addCssFile);
94 }
95 }
96 if (is_array($includeJsFiles) && count($includeJsFiles) > 0) {
97 foreach ($includeJsFiles as $addJsFile) {
98 $pageRenderer->addJsFile($addJsFile);
99 }
100 }
101 if (is_array($includeRequireJsModules) && count($includeRequireJsModules) > 0) {
102 foreach ($includeRequireJsModules as $addRequireJsFile) {
103 $pageRenderer->loadRequireJsModule($addRequireJsFile);
104 }
105 }
106 // Add inline language labels
107 if (is_array($addJsInlineLabels) && count($addJsInlineLabels) > 0) {
108 $extensionKey = $this->renderingContext->getControllerContext()->getRequest()->getControllerExtensionKey();
109 foreach ($addJsInlineLabels as $key) {
110 $label = LocalizationUtility::translate($key, $extensionKey);
111 $pageRenderer->addInlineLanguageLabel($key, $label);
112 }
113 }
114 // Render the content and return it
115 $output = $this->renderChildren();
116 $output = $doc->startPage($pageTitle) . $output;
117 $output .= $doc->endPage();
118 return $output;
119 }
120 }