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