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