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