[TASK] Remove superfluous parenthesis in sysexts
[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 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 * The form wizard view
28 *
29 * @category View
30 * @package TYPO3
31 * @subpackage form
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, because this will be used by
40 * the TYPO3 Backend Template Class typo3/template.php
41 *
42 * @var \TYPO3\CMS\Backend\Template\MediumDocumentTemplate
43 */
44 public $doc;
45
46 /**
47 * Constructs this view
48 *
49 * Defines the global variable SOBE. Normally this is used by the wizards
50 * which are one file only. SOBE is used by typo3/template.php. This view is
51 * now the class with the global variable name SOBE.
52 *
53 * Defines the document template object.
54 *
55 * @return void
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.xml');
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', 1));
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\Extension\ExtensionManager::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/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 );
220 // Load ExtJS
221 $this->pageRenderer->loadExtJS();
222 // Load the wizards javascript
223 foreach ($javascriptFiles as $javascriptFile) {
224 $this->pageRenderer->addJsFile($baseUrl . $javascriptFile, 'text/javascript', $compress, FALSE);
225 }
226 }
227
228 /**
229 * Load the necessarry css
230 *
231 * This will only be done when the referenced record is available
232 *
233 * @return void
234 */
235 protected function loadCss() {
236 // TODO Set to TRUE when finished
237 $compress = FALSE;
238 $baseUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath('../../../../../' . \TYPO3\CMS\Core\Extension\ExtensionManager::siteRelPath('form') . 'Resources/Public/CSS/');
239 $cssFiles = array(
240 'Wizard/Form.css',
241 'Wizard/Wizard.css'
242 );
243 // Load the wizards css
244 foreach ($cssFiles as $cssFile) {
245 $this->pageRenderer->addCssFile($baseUrl . $cssFile, 'stylesheet', 'all', '', $compress, FALSE);
246 }
247 }
248
249 /**
250 * Load the settings
251 *
252 * The settings are defined in pageTSconfig mod.wizards.form
253 *
254 * @return void
255 */
256 protected function loadSettings() {
257 $record = $this->repository->getRecord();
258 $pageId = $record->getPageId();
259 $modTSconfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig($pageId, 'mod.wizards.form');
260 $settings = $modTSconfig['properties'];
261 $this->removeTrailingDotsFromTyposcript($settings);
262 $this->doc->JScode .= $this->doc->wrapScriptTags('TYPO3.Form.Wizard.Settings = ' . json_encode($settings) . ';');
263 }
264
265 /**
266 * Reads locallang file into array (for possible include in header)
267 *
268 * @param $file
269 */
270 protected function loadLocalization() {
271 $wizardLabels = $GLOBALS['LANG']->includeLLFile('EXT:form/Resources/Private/Language/locallang_wizard.xml', FALSE, TRUE);
272 $controllerLabels = $GLOBALS['LANG']->includeLLFile('EXT:form/Resources/Private/Language/locallang_controller.xml', FALSE, TRUE);
273 $labels = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($controllerLabels, $wizardLabels);
274 $this->pageRenderer->addInlineLanguageLabelArray($labels['default']);
275 }
276
277 /**
278 * Hook to extend the wizard interface.
279 *
280 * The hook is called just before content rendering. Use it by adding your function to the array
281 * $TYPO3_CONF_VARS['EXTCONF']['form']['hooks']['renderWizard']
282 *
283 * @return void
284 */
285 protected function callRenderHook() {
286 $params = array();
287 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['form']['hooks']['renderWizard'])) {
288 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['form']['hooks']['renderWizard'] as $funcRef) {
289 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
290 }
291 }
292 }
293
294 /**
295 * Remove the trailing dots from the values in Typoscript
296 *
297 * @param array $array The array with the trailing dots
298 */
299 protected function removeTrailingDotsFromTyposcript(array &$array) {
300 foreach ($array as $key => $value) {
301 if (is_array($value)) {
302 $this->removeTrailingDotsFromTyposcript($value);
303 }
304 if (substr($key, -1) === '.') {
305 $newKey = substr($key, 0, -1);
306 unset($array[$key]);
307 $array[$newKey] = $value;
308 }
309 }
310 }
311
312 /**
313 * Create the panel of buttons for submitting the form or otherwise perform
314 * operations.
315 *
316 * @return array all available buttons as an assoc. array
317 */
318 protected function getButtons() {
319 $buttons = array(
320 'csh' => '',
321 'csh_buttons' => '',
322 'close' => '',
323 'save' => '',
324 'save_close' => '',
325 'reload' => ''
326 );
327 // CSH
328 $buttons['csh'] = \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz', $GLOBALS['BACK_PATH'], '');
329 // CSH Buttons
330 $buttons['csh_buttons'] = \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_buttons', $GLOBALS['BACK_PATH'], '');
331 // Close
332 $getPostVariables = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('P');
333 $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(
334 'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc', TRUE)
335 )) . '</a>';
336 return $buttons;
337 }
338
339 /**
340 * Generate the body content
341 *
342 * If there is an error, no reference to a record, a Flash Message will be
343 * displayed
344 *
345 * @return string The body content
346 */
347 protected function getBodyContent() {
348 if ($this->recordIsAvailable) {
349 $bodyContent = '';
350 } else {
351 /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
352 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('errorMessage', 1), $GLOBALS['LANG']->getLL('errorTitle', 1), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
353 $bodyContent = $flashMessage->render();
354 }
355 return $bodyContent;
356 }
357
358 }
359
360
361 ?>