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