2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Utility\GeneralUtility
;
18 use TYPO3\CMS\Extbase\Utility\LocalizationUtility
;
21 * View helper which allows you to create extbase based modules in the style of TYPO3 default modules.
25 * <code title="Simple">
26 * <f:be.container>your module content</f:be.container>
29 * "your module content" wrapped with proper head & body tags.
30 * Default backend CSS styles and JavaScript will be included
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>
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.
43 class ContainerViewHelper
extends AbstractBackendViewHelper
48 protected $escapeOutput = false;
51 * Initialize arguments.
53 * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
55 public function initializeArguments()
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');
66 * Render start page with \TYPO3\CMS\Backend\Template\DocumentTemplate and pageTitle
69 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
70 * @see \TYPO3\CMS\Core\Page\PageRenderer
72 public function render()
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'];
80 $pageRenderer = $this->getPageRenderer();
81 $doc = $this->getDocInstance();
82 $doc->JScode
.= GeneralUtility
::wrapJS($doc->redirectUrls());
84 // Include custom CSS and JS files
85 if (is_array($includeCssFiles) && count($includeCssFiles) > 0) {
86 foreach ($includeCssFiles as $addCssFile) {
87 $pageRenderer->addCssFile($addCssFile);
90 if (is_array($includeJsFiles) && count($includeJsFiles) > 0) {
91 foreach ($includeJsFiles as $addJsFile) {
92 $pageRenderer->addJsFile($addJsFile);
95 if (is_array($includeRequireJsModules) && count($includeRequireJsModules) > 0) {
96 foreach ($includeRequireJsModules as $addRequireJsFile) {
97 $pageRenderer->loadRequireJsModule($addRequireJsFile);
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);
108 // Render the content and return it
109 $output = $this->renderChildren();
110 $output = $doc->startPage($pageTitle) . $output;
111 $output .= $doc->endPage();