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