[TASK] Deprecate jQuery and extJS arguments for BE viewhelpers
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / PageRendererViewHelper.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 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
21
22 /**
23 * View helper which allows you to create extbase based modules in the style of TYPO3 default modules.
24 *
25 * = Examples =
26 *
27 * <code title="All options">
28 * <f:be.pageRenderer pageTitle="foo" 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'}" />
29 * </code>
30 * <output>
31 *
32 * Custom CSS file EXT:your_extension/Resources/Public/Css/styles.css and
33 * JavaScript files EXT:your_extension/Resources/Public/JavaScript/Library1.js and EXT:your_extension/Resources/Public/JavaScript/Library2.js
34 * will be loaded, plus ExtJS and jQuery and some inline labels for usage in JS code.
35 * </output>
36 */
37 class PageRendererViewHelper extends AbstractViewHelper
38 {
39 /**
40 * @var PageRenderer
41 */
42 protected $pageRenderer;
43
44 /**
45 * @param PageRenderer $pageRenderer
46 */
47 public function injectPageRenderer(PageRenderer $pageRenderer)
48 {
49 $this->pageRenderer = $pageRenderer;
50 }
51
52 /**
53 * Initialize arguments.
54 *
55 * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
56 */
57 public function initializeArguments()
58 {
59 parent::initializeArguments();
60 $this->registerArgument('pageTitle', 'string', 'title tag of the module. Not required by default, as BE modules are shown in a frame', false, '');
61 $this->registerArgument('loadExtJs', 'bool', 'specifies whether to load ExtJS library. Defaults to FALSE. This option will be removed in TYPO3 v9', false, false);
62 $this->registerArgument('loadExtJsTheme', 'bool', 'whether to load ExtJS "grey" theme. Defaults to FALSE. This option will be removed in TYPO3 v9', false, true);
63 $this->registerArgument('enableExtJsDebug', 'bool', 'if TRUE, debug version of ExtJS is loaded. Use this for development only. This option will be removed in TYPO3 v9', false, false);
64 $this->registerArgument('loadJQuery', 'bool', 'whether to load jQuery library. Defaults to FALSE. This option will be removed in TYPO3 v9', 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. This option will be removed in TYPO3 v9');
70 }
71
72 /**
73 * Render start page with \TYPO3\CMS\Backend\Template\DocumentTemplate and pageTitle
74 */
75 public function render()
76 {
77 $pageTitle = $this->arguments['pageTitle'];
78 $loadExtJs = $this->arguments['loadExtJs'];
79 $loadExtJsTheme = $this->arguments['loadExtJsTheme'];
80 $enableExtJsDebug = $this->arguments['enableExtJsDebug'];
81 $loadJQuery = $this->arguments['loadJQuery'];
82 $includeCssFiles = $this->arguments['includeCssFiles'];
83 $includeJsFiles = $this->arguments['includeJsFiles'];
84 $addJsInlineLabels = $this->arguments['addJsInlineLabels'];
85 $includeRequireJsModules = $this->arguments['includeRequireJsModules'];
86 $jQueryNamespace = $this->arguments['jQueryNamespace'];
87
88 if ($pageTitle) {
89 $this->pageRenderer->setTitle($pageTitle);
90 }
91 if ($loadExtJs) {
92 GeneralUtility::logDeprecatedViewHelperAttribute(
93 'loadExtJs',
94 $this->renderingContext,
95 'Setting "loadExtJs" and "loadExtJsTheme" in PageRenderer ViewHelper is deprecated, the option will be removed in TYPO3 v9'
96 );
97 $this->pageRenderer->loadExtJS(true, $loadExtJsTheme);
98 if ($enableExtJsDebug) {
99 GeneralUtility::logDeprecatedViewHelperAttribute(
100 'enableExtJsDebug',
101 $this->renderingContext,
102 'Setting "enableExtJsDebug" in PageRenderer ViewHelper is deprecated, the option will be removed in TYPO3 v9'
103 );
104 $this->pageRenderer->enableExtJsDebug();
105 }
106 }
107 if ($loadJQuery) {
108 GeneralUtility::logDeprecatedViewHelperAttribute(
109 'loadjQuery',
110 $this->renderingContext,
111 'Setting "loadjQuery" and "jQueryNamespace" in PageRenderer ViewHelper are deprecated, the option will be removed in TYPO3 v9'
112 );
113 $jQueryNamespace = $jQueryNamespace ?: PageRenderer::JQUERY_NAMESPACE_DEFAULT;
114 $this->pageRenderer->loadJquery(null, null, $jQueryNamespace);
115 }
116 // Include custom CSS and JS files
117 if (is_array($includeCssFiles) && count($includeCssFiles) > 0) {
118 foreach ($includeCssFiles as $addCssFile) {
119 $this->pageRenderer->addCssFile($addCssFile);
120 }
121 }
122 if (is_array($includeJsFiles) && count($includeJsFiles) > 0) {
123 foreach ($includeJsFiles as $addJsFile) {
124 $this->pageRenderer->addJsFile($addJsFile);
125 }
126 }
127 if (is_array($includeRequireJsModules) && count($includeRequireJsModules) > 0) {
128 foreach ($includeRequireJsModules as $addRequireJsFile) {
129 $this->pageRenderer->loadRequireJsModule($addRequireJsFile);
130 }
131 }
132 // Add inline language labels
133 if (is_array($addJsInlineLabels) && count($addJsInlineLabels) > 0) {
134 $extensionKey = $this->controllerContext->getRequest()->getControllerExtensionKey();
135 foreach ($addJsInlineLabels as $key) {
136 $label = LocalizationUtility::translate($key, $extensionKey);
137 $this->pageRenderer->addInlineLanguageLabel($key, $label);
138 }
139 }
140 }
141 }