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\Page\PageRenderer
;
18 use TYPO3\CMS\Extbase\Utility\LocalizationUtility
;
19 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
;
22 * View helper which allows you to create extbase based modules in the style of TYPO3 default modules.
26 * <code title="All options">
27 * <f:be.pageRenderer 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'}" />
31 * Custom CSS file EXT:your_extension/Resources/Public/Css/styles.css and
32 * JavaScript files EXT:your_extension/Resources/Public/JavaScript/Library1.js and EXT:your_extension/Resources/Public/JavaScript/Library2.js
33 * will be loaded, plus some inline labels for usage in JS code.
36 class PageRendererViewHelper
extends AbstractViewHelper
41 protected $pageRenderer;
44 * @param PageRenderer $pageRenderer
46 public function injectPageRenderer(PageRenderer
$pageRenderer)
48 $this->pageRenderer
= $pageRenderer;
52 * Initialize arguments.
54 * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
56 public function initializeArguments()
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('includeCssFiles', 'array', 'List of custom CSS file to be loaded');
61 $this->registerArgument('includeJsFiles', 'array', 'List of custom JavaScript file to be loaded');
62 $this->registerArgument('addJsInlineLabels', 'array', 'Custom labels to add to JavaScript inline labels');
63 $this->registerArgument('includeRequireJsModules', 'array', 'List of RequireJS modules to be loaded');
64 $this->registerArgument('addInlineSettings', 'array', 'Adds Javascript Inline Setting');
68 * Render start page with \TYPO3\CMS\Backend\Template\DocumentTemplate and pageTitle
70 public function render()
72 $pageTitle = $this->arguments
['pageTitle'];
73 $includeCssFiles = $this->arguments
['includeCssFiles'];
74 $includeJsFiles = $this->arguments
['includeJsFiles'];
75 $addJsInlineLabels = $this->arguments
['addJsInlineLabels'];
76 $includeRequireJsModules = $this->arguments
['includeRequireJsModules'];
77 $addInlineSettings = $this->arguments
['addInlineSettings'];
80 $this->pageRenderer
->setTitle($pageTitle);
82 // Include custom CSS and JS files
83 if (is_array($includeCssFiles) && count($includeCssFiles) > 0) {
84 foreach ($includeCssFiles as $addCssFile) {
85 $this->pageRenderer
->addCssFile($addCssFile);
88 if (is_array($includeJsFiles) && count($includeJsFiles) > 0) {
89 foreach ($includeJsFiles as $addJsFile) {
90 $this->pageRenderer
->addJsFile($addJsFile);
93 if (is_array($includeRequireJsModules) && count($includeRequireJsModules) > 0) {
94 foreach ($includeRequireJsModules as $addRequireJsFile) {
95 $this->pageRenderer
->loadRequireJsModule($addRequireJsFile);
99 if (is_array($addInlineSettings) && count($addInlineSettings) > 0) {
100 $this->pageRenderer
->addInlineSettingArray(null, $addInlineSettings);
103 // Add inline language labels
104 if (is_array($addJsInlineLabels) && count($addJsInlineLabels) > 0) {
105 $extensionKey = $this->controllerContext
->getRequest()->getControllerExtensionKey();
106 foreach ($addJsInlineLabels as $key) {
107 $label = LocalizationUtility
::translate($key, $extensionKey);
108 $this->pageRenderer
->addInlineLanguageLabel($key, $label);