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