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