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