[TASK] Call explicit render() on icon objects
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / View / Wizard / WizardView.php
1 <?php
2 namespace TYPO3\CMS\Form\View\Wizard;
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\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Imaging\Icon;
19 use TYPO3\CMS\Core\Imaging\IconFactory;
20 use TYPO3\CMS\Core\Messaging\FlashMessage;
21 use TYPO3\CMS\Core\Page\PageRenderer;
22 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24
25 /**
26 * The form wizard view
27 */
28 class WizardView extends \TYPO3\CMS\Form\View\Wizard\AbstractWizardView {
29
30 /**
31 * The document template object
32 *
33 * Needs to be a local variable of the class.
34 *
35 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
36 */
37 public $doc;
38
39 /**
40 * @var PageRenderer
41 */
42 protected $pageRenderer;
43
44 /**
45 * Constructs this view
46 *
47 * Defines the global variable SOBE. Normally this is used by the wizards
48 * which are one file only. This view is now the class with the global
49 * variable name SOBE.
50 *
51 * Defines the document template object.
52 *
53 * @param \TYPO3\CMS\Form\Domain\Repository\ContentRepository $repository
54 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
55 */
56 public function __construct(\TYPO3\CMS\Form\Domain\Repository\ContentRepository $repository) {
57 parent::__construct($repository);
58 $GLOBALS['SOBE'] = $this;
59 // Define the document template object
60 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
61 $this->doc->setModuleTemplate('EXT:form/Resources/Private/Templates/Wizard.html');
62 }
63
64 /**
65 * The main render method
66 *
67 * Gathers all content and echos it to the screen
68 *
69 * @return void
70 */
71 public function render() {
72 $docHeaderButtons = array();
73 // Check if the referenced record is available
74 $this->recordIsAvailable = $this->repository->hasRecord();
75 if ($this->recordIsAvailable) {
76 // Load necessary JavaScript
77 $this->loadJavascript();
78 // Load necessary CSS
79 $this->loadCss();
80 // Load the settings
81 $this->loadSettings();
82 // Localization
83 $this->loadLocalization();
84 // Setting up the buttons and markers for docheader
85 $docHeaderButtons = $this->getButtons();
86 $markers['CSH'] = $docHeaderButtons['csh'];
87 // Hook
88 $this->callRenderHook();
89 }
90 // Getting the body content
91 $markers['CONTENT'] = $this->getBodyContent();
92 // Build the HTML for the module
93 $content = $this->doc->startPage($this->getLanguageService()->getLL('title', TRUE));
94 $content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markers);
95 $content .= $this->doc->endPage();
96 $content = $this->doc->insertStylesAndJS($content);
97
98 echo $content;
99 die;
100 }
101
102 /**
103 * Load the necessary javascript
104 *
105 * This will only be done when the referenced record is available
106 *
107 * @return void
108 */
109 protected function loadJavascript() {
110 $compress = TRUE;
111 $javascriptFiles = array(
112 'Initialize.js',
113 'Ux/Ext.ux.merge.js',
114 'Ux/Ext.ux.isemptyobject.js',
115 'Ux/Ext.ux.spinner.js',
116 'Ux/Ext.ux.form.spinnerfield.js',
117 'Ux/Ext.ux.form.textfieldsubmit.js',
118 'Ux/Ext.ux.grid.CheckColumn.js',
119 'Ux/Ext.ux.grid.SingleSelectCheckColumn.js',
120 'Ux/Ext.ux.grid.ItemDeleter.js',
121 'Helpers/History.js',
122 'Helpers/Element.js',
123 'Elements/ButtonGroup.js',
124 'Elements/Container.js',
125 'Elements/Elements.js',
126 'Elements/Dummy.js',
127 'Elements/Basic/Button.js',
128 'Elements/Basic/Checkbox.js',
129 'Elements/Basic/Fieldset.js',
130 'Elements/Basic/Fileupload.js',
131 'Elements/Basic/Form.js',
132 'Elements/Basic/Hidden.js',
133 'Elements/Basic/Password.js',
134 'Elements/Basic/Radio.js',
135 'Elements/Basic/Reset.js',
136 'Elements/Basic/Select.js',
137 'Elements/Basic/Submit.js',
138 'Elements/Basic/Textarea.js',
139 'Elements/Basic/Textline.js',
140 'Elements/Predefined/Email.js',
141 'Elements/Predefined/CheckboxGroup.js',
142 'Elements/Predefined/Name.js',
143 'Elements/Predefined/RadioGroup.js',
144 'Elements/Content/Header.js',
145 'Elements/Content/Textblock.js',
146 'Viewport.js',
147 'Viewport/Left.js',
148 'Viewport/Right.js',
149 'Viewport/Left/Elements.js',
150 'Viewport/Left/Elements/ButtonGroup.js',
151 'Viewport/Left/Elements/Basic.js',
152 'Viewport/Left/Elements/Predefined.js',
153 'Viewport/Left/Elements/Content.js',
154 'Viewport/Left/Options.js',
155 'Viewport/Left/Options/Dummy.js',
156 'Viewport/Left/Options/Panel.js',
157 'Viewport/Left/Options/Forms/Attributes.js',
158 'Viewport/Left/Options/Forms/Label.js',
159 'Viewport/Left/Options/Forms/Legend.js',
160 'Viewport/Left/Options/Forms/Options.js',
161 'Viewport/Left/Options/Forms/Various.js',
162 'Viewport/Left/Options/Forms/Filters.js',
163 'Viewport/Left/Options/Forms/Filters/Filter.js',
164 'Viewport/Left/Options/Forms/Filters/Dummy.js',
165 'Viewport/Left/Options/Forms/Filters/Alphabetic.js',
166 'Viewport/Left/Options/Forms/Filters/Alphanumeric.js',
167 'Viewport/Left/Options/Forms/Filters/Currency.js',
168 'Viewport/Left/Options/Forms/Filters/Digit.js',
169 'Viewport/Left/Options/Forms/Filters/Integer.js',
170 'Viewport/Left/Options/Forms/Filters/LowerCase.js',
171 'Viewport/Left/Options/Forms/Filters/RegExp.js',
172 'Viewport/Left/Options/Forms/Filters/RemoveXSS.js',
173 'Viewport/Left/Options/Forms/Filters/StripNewLines.js',
174 'Viewport/Left/Options/Forms/Filters/TitleCase.js',
175 'Viewport/Left/Options/Forms/Filters/Trim.js',
176 'Viewport/Left/Options/Forms/Filters/UpperCase.js',
177 'Viewport/Left/Options/Forms/Validation.js',
178 'Viewport/Left/Options/Forms/Validation/Rule.js',
179 'Viewport/Left/Options/Forms/Validation/Dummy.js',
180 'Viewport/Left/Options/Forms/Validation/Alphabetic.js',
181 'Viewport/Left/Options/Forms/Validation/Alphanumeric.js',
182 'Viewport/Left/Options/Forms/Validation/Between.js',
183 'Viewport/Left/Options/Forms/Validation/Date.js',
184 'Viewport/Left/Options/Forms/Validation/Digit.js',
185 'Viewport/Left/Options/Forms/Validation/Email.js',
186 'Viewport/Left/Options/Forms/Validation/Equals.js',
187 'Viewport/Left/Options/Forms/Validation/FileAllowedTypes.js',
188 'Viewport/Left/Options/Forms/Validation/FileMaximumSize.js',
189 'Viewport/Left/Options/Forms/Validation/FileMinimumSize.js',
190 'Viewport/Left/Options/Forms/Validation/Float.js',
191 'Viewport/Left/Options/Forms/Validation/GreaterThan.js',
192 'Viewport/Left/Options/Forms/Validation/InArray.js',
193 'Viewport/Left/Options/Forms/Validation/Integer.js',
194 'Viewport/Left/Options/Forms/Validation/Ip.js',
195 'Viewport/Left/Options/Forms/Validation/Length.js',
196 'Viewport/Left/Options/Forms/Validation/LessThan.js',
197 'Viewport/Left/Options/Forms/Validation/RegExp.js',
198 'Viewport/Left/Options/Forms/Validation/Required.js',
199 'Viewport/Left/Options/Forms/Validation/Uri.js',
200 'Viewport/Left/Form.js',
201 'Viewport/Left/Form/Behaviour.js',
202 'Viewport/Left/Form/Attributes.js',
203 'Viewport/Left/Form/Prefix.js',
204 'Viewport/Left/Form/PostProcessor.js',
205 'Viewport/Left/Form/PostProcessors/PostProcessor.js',
206 'Viewport/Left/Form/PostProcessors/Dummy.js',
207 'Viewport/Left/Form/PostProcessors/Mail.js',
208 'Viewport/Left/Form/PostProcessors/Redirect.js'
209 );
210 // Load ExtJS
211 $this->getPageRenderer()->loadExtJS();
212 // Load the wizards javascript
213 $baseUrl = ExtensionManagementUtility::extRelPath('form') . 'Resources/Public/JavaScript/Wizard/';
214 foreach ($javascriptFiles as $javascriptFile) {
215 $this->getPageRenderer()->addJsFile($baseUrl . $javascriptFile, 'text/javascript', $compress, FALSE);
216 }
217 }
218
219 /**
220 * Load the necessary css
221 *
222 * This will only be done when the referenced record is available
223 *
224 * @return void
225 */
226 protected function loadCss() {
227 // @todo Set to TRUE when finished
228 $compress = FALSE;
229 $cssFiles = array(
230 'Wizard/Form.css',
231 'Wizard/Wizard.css'
232 );
233 $baseUrl = ExtensionManagementUtility::extRelPath('form') . 'Resources/Public/CSS/';
234 // Load the wizards css
235 foreach ($cssFiles as $cssFile) {
236 $this->getPageRenderer()->addCssFile($baseUrl . $cssFile, 'stylesheet', 'all', '', $compress, FALSE);
237 }
238 }
239
240 /**
241 * Load the settings
242 *
243 * The settings are defined in pageTSconfig mod.wizards.form
244 *
245 * @return void
246 */
247 protected function loadSettings() {
248 $record = $this->repository->getRecord();
249 $pageId = $record->getPageId();
250 $modTSconfig = BackendUtility::getModTSconfig($pageId, 'mod.wizards.form');
251 $settings = $modTSconfig['properties'];
252 $this->removeTrailingDotsFromTyposcript($settings);
253 $this->doc->JScode .= $this->doc->wrapScriptTags('TYPO3.Form.Wizard.Settings = ' . json_encode($settings) . ';');
254 }
255
256 /**
257 * Reads locallang file into array (for possible include in header)
258 *
259 * @return void
260 */
261 protected function loadLocalization() {
262 $wizardLabels = $this->getLanguageService()->includeLLFile('EXT:form/Resources/Private/Language/locallang_wizard.xlf', FALSE, TRUE);
263 $controllerLabels = $this->getLanguageService()->includeLLFile('EXT:form/Resources/Private/Language/locallang.xlf', FALSE, TRUE);
264 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($controllerLabels, $wizardLabels);
265 $this->getPageRenderer()->addInlineLanguageLabelArray($controllerLabels['default']);
266 }
267
268 /**
269 * Hook to extend the wizard interface.
270 *
271 * The hook is called just before content rendering. Use it by adding your function to the array
272 * $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['form']['hooks']['renderWizard']
273 *
274 * @return void
275 */
276 protected function callRenderHook() {
277 $params = array();
278 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['form']['hooks']['renderWizard'])) {
279 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['form']['hooks']['renderWizard'] as $funcRef) {
280 GeneralUtility::callUserFunction($funcRef, $params, $this);
281 }
282 }
283 }
284
285 /**
286 * Remove the trailing dots from the values in Typoscript
287 *
288 * @param array $array The array with the trailing dots
289 * @return void
290 */
291 protected function removeTrailingDotsFromTyposcript(array &$array) {
292 foreach ($array as $key => $value) {
293 if (is_array($value)) {
294 $this->removeTrailingDotsFromTyposcript($value);
295 }
296 if (substr($key, -1) === '.') {
297 $newKey = substr($key, 0, -1);
298 unset($array[$key]);
299 $array[$newKey] = $value;
300 }
301 }
302 }
303
304 /**
305 * Create the panel of buttons for submitting the form or otherwise perform
306 * operations.
307 *
308 * @return array all available buttons as an assoc. array
309 */
310 protected function getButtons() {
311 /** @var IconFactory $iconFactory */
312 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
313
314 $buttons = array(
315 'csh' => '',
316 'csh_buttons' => '',
317 'close' => '',
318 'save' => '',
319 'save_close' => '',
320 'reload' => ''
321 );
322 // CSH
323 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz');
324 // CSH Buttons
325 $buttons['csh_buttons'] = BackendUtility::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_buttons');
326 // Close
327 $getPostVariables = GeneralUtility::_GP('P');
328 $title = 'title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '"';
329 $onClick = htmlspecialchars('jumpToUrl(unescape(\'' .
330 rawurlencode(GeneralUtility::sanitizeLocalUrl($getPostVariables['returnUrl'])) . '\')); return false;');
331 $buttons['close'] = '<a href="#" onclick="' . $onClick . '" ' . $title . '>' .
332 $iconFactory->getIcon('actions-document-close', Icon::SIZE_SMALL)->render() . '</a>';
333 return $buttons;
334 }
335
336 /**
337 * Generate the body content
338 *
339 * If there is an error, no reference to a record, a Flash Message will be
340 * displayed
341 *
342 * @return string The body content
343 */
344 protected function getBodyContent() {
345 if ($this->recordIsAvailable) {
346 $bodyContent = '';
347 } else {
348 /** @var $flashMessage FlashMessage */
349 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class,
350 $this->getLanguageService()->getLL('errorMessage', TRUE),
351 $this->getLanguageService()->getLL('errorTitle', TRUE),
352 FlashMessage::ERROR);
353 $bodyContent = $flashMessage->render();
354 }
355 return $bodyContent;
356 }
357
358 /**
359 * @return PageRenderer
360 */
361 protected function getPageRenderer() {
362 if (!isset($this->pageRenderer)) {
363 $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
364 }
365
366 return $this->pageRenderer;
367 }
368
369 }