TYPO3  7.6
WizardView.php
Go to the documentation of this file.
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 
25 
30 {
36  protected $recordIsAvailable = false;
37 
41  protected $repository;
42 
50  public $doc;
51 
55  protected $pageRenderer;
56 
70  {
71  $this->setRepository($repository);
72  $this->getLanguageService()->includeLLFile('EXT:form/Resources/Private/Language/locallang_wizard.xlf');
73  $GLOBALS['SOBE'] = $this;
74  // Define the document template object
75  $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
76  $this->doc->setModuleTemplate('EXT:form/Resources/Private/Templates/Wizard.html');
77  }
78 
86  {
87  $this->repository = $repository;
88  }
96  public function render()
97  {
98  $docHeaderButtons = array();
99  // Check if the referenced record is available
100  $this->recordIsAvailable = $this->repository->hasRecord();
101  if ($this->recordIsAvailable) {
102  // Load necessary JavaScript
103  $this->loadJavascript();
104  // Load necessary CSS
105  $this->loadCss();
106  // Load the settings
107  $this->loadSettings();
108  // Localization
109  $this->loadLocalization();
110  // Setting up the buttons and markers for docheader
111  $docHeaderButtons = $this->getButtons();
112  $markers['CSH'] = $docHeaderButtons['csh'];
113  // Hook
114  $this->callRenderHook();
115  }
116  // Getting the body content
117  $markers['CONTENT'] = $this->getBodyContent();
118  // Build the HTML for the module
119  $content = $this->doc->startPage($this->getLanguageService()->getLL('title', true));
120  $content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markers);
121  $content .= $this->doc->endPage();
122  return $this->doc->insertStylesAndJS($content);
123  }
124 
132  protected function loadJavascript()
133  {
134  $compress = true;
135  $javascriptFiles = array(
136  'Initialize.js',
137  'Ux/Ext.ux.merge.js',
138  'Ux/Ext.ux.isemptyobject.js',
139  'Ux/Ext.ux.spinner.js',
140  'Ux/Ext.ux.form.spinnerfield.js',
141  'Ux/Ext.ux.form.textfieldsubmit.js',
142  'Ux/Ext.ux.form.ValueCheckbox.js', // required by Viewport/Left/Options/Forms/Attributes.js
143  'Ux/Ext.ux.grid.CheckColumn.js',
144  'Ux/Ext.ux.grid.SingleSelectCheckColumn.js',
145  'Ux/Ext.ux.grid.ItemDeleter.js',
146  'Helpers/History.js',
147  'Helpers/Element.js',
148  'Elements/ButtonGroup.js',
149  'Elements/Container.js',
150  'Elements/Elements.js',
151  'Elements/Dummy.js',
152  'Elements/Basic/Button.js',
153  'Elements/Basic/Checkbox.js',
154  'Elements/Basic/Fieldset.js',
155  'Elements/Basic/Fileupload.js',
156  'Elements/Basic/Form.js',
157  'Elements/Basic/Hidden.js',
158  'Elements/Basic/Password.js',
159  'Elements/Basic/Radio.js',
160  'Elements/Basic/Reset.js',
161  'Elements/Basic/Select.js',
162  'Elements/Basic/Submit.js',
163  'Elements/Basic/Textarea.js',
164  'Elements/Basic/Textline.js',
165  'Elements/Predefined/Email.js',
166  'Elements/Predefined/CheckboxGroup.js',
167  'Elements/Predefined/Name.js',
168  'Elements/Predefined/RadioGroup.js',
169  'Elements/Content/Header.js',
170  'Elements/Content/Textblock.js',
171  'Viewport.js',
172  'Viewport/Left.js',
173  'Viewport/Right.js',
174  'Viewport/Left/Elements.js',
175  'Viewport/Left/Elements/ButtonGroup.js',
176  'Viewport/Left/Elements/Basic.js',
177  'Viewport/Left/Elements/Predefined.js',
178  'Viewport/Left/Elements/Content.js',
179  'Viewport/Left/Options.js',
180  'Viewport/Left/Options/Dummy.js',
181  'Viewport/Left/Options/Panel.js',
182  'Viewport/Left/Options/Forms/Attributes.js',
183  'Viewport/Left/Options/Forms/Label.js',
184  'Viewport/Left/Options/Forms/Legend.js',
185  'Viewport/Left/Options/Forms/Options.js',
186  'Viewport/Left/Options/Forms/Various.js',
187  'Viewport/Left/Options/Forms/Filters.js',
188  'Viewport/Left/Options/Forms/Filters/Filter.js',
189  'Viewport/Left/Options/Forms/Filters/Dummy.js',
190  'Viewport/Left/Options/Forms/Filters/Alphabetic.js',
191  'Viewport/Left/Options/Forms/Filters/Alphanumeric.js',
192  'Viewport/Left/Options/Forms/Filters/Currency.js',
193  'Viewport/Left/Options/Forms/Filters/Digit.js',
194  'Viewport/Left/Options/Forms/Filters/Integer.js',
195  'Viewport/Left/Options/Forms/Filters/LowerCase.js',
196  'Viewport/Left/Options/Forms/Filters/RegExp.js',
197  'Viewport/Left/Options/Forms/Filters/RemoveXSS.js',
198  'Viewport/Left/Options/Forms/Filters/StripNewLines.js',
199  'Viewport/Left/Options/Forms/Filters/TitleCase.js',
200  'Viewport/Left/Options/Forms/Filters/Trim.js',
201  'Viewport/Left/Options/Forms/Filters/UpperCase.js',
202  'Viewport/Left/Options/Forms/Validation.js',
203  'Viewport/Left/Options/Forms/Validation/Rule.js',
204  'Viewport/Left/Options/Forms/Validation/Dummy.js',
205  'Viewport/Left/Options/Forms/Validation/Alphabetic.js',
206  'Viewport/Left/Options/Forms/Validation/Alphanumeric.js',
207  'Viewport/Left/Options/Forms/Validation/Between.js',
208  'Viewport/Left/Options/Forms/Validation/Date.js',
209  'Viewport/Left/Options/Forms/Validation/Digit.js',
210  'Viewport/Left/Options/Forms/Validation/Email.js',
211  'Viewport/Left/Options/Forms/Validation/Equals.js',
212  'Viewport/Left/Options/Forms/Validation/FileAllowedTypes.js',
213  'Viewport/Left/Options/Forms/Validation/FileMaximumSize.js',
214  'Viewport/Left/Options/Forms/Validation/FileMinimumSize.js',
215  'Viewport/Left/Options/Forms/Validation/Float.js',
216  'Viewport/Left/Options/Forms/Validation/GreaterThan.js',
217  'Viewport/Left/Options/Forms/Validation/InArray.js',
218  'Viewport/Left/Options/Forms/Validation/Integer.js',
219  'Viewport/Left/Options/Forms/Validation/Ip.js',
220  'Viewport/Left/Options/Forms/Validation/Length.js',
221  'Viewport/Left/Options/Forms/Validation/LessThan.js',
222  'Viewport/Left/Options/Forms/Validation/RegExp.js',
223  'Viewport/Left/Options/Forms/Validation/Required.js',
224  'Viewport/Left/Options/Forms/Validation/Uri.js',
225  'Viewport/Left/Form.js',
226  'Viewport/Left/Form/Behaviour.js',
227  'Viewport/Left/Form/Attributes.js',
228  'Viewport/Left/Form/Prefix.js',
229  'Viewport/Left/Form/PostProcessor.js',
230  'Viewport/Left/Form/PostProcessors/PostProcessor.js',
231  'Viewport/Left/Form/PostProcessors/Dummy.js',
232  'Viewport/Left/Form/PostProcessors/Mail.js',
233  'Viewport/Left/Form/PostProcessors/Redirect.js'
234  );
235  // Load ExtJS
236  $this->getPageRenderer()->loadExtJS();
237  // Load the wizards javascript
238  $baseUrl = ExtensionManagementUtility::extRelPath('form') . 'Resources/Public/JavaScript/Wizard/';
239  foreach ($javascriptFiles as $javascriptFile) {
240  $this->getPageRenderer()->addJsFile($baseUrl . $javascriptFile, 'text/javascript', $compress, false);
241  }
242  }
243 
251  protected function loadCss()
252  {
253  // @todo Set to TRUE when finished
254  $compress = false;
255  $cssFiles = array(
256  'Wizard/Form.css',
257  'Wizard/Wizard.css'
258  );
259  $baseUrl = ExtensionManagementUtility::extRelPath('form') . 'Resources/Public/CSS/';
260  // Load the wizards css
261  foreach ($cssFiles as $cssFile) {
262  $this->getPageRenderer()->addCssFile($baseUrl . $cssFile, 'stylesheet', 'all', '', $compress, false);
263  }
264  }
265 
273  protected function loadSettings()
274  {
275  $record = $this->repository->getRecord();
276  $pageId = $record->getPageId();
277  $modTSconfig = BackendUtility::getModTSconfig($pageId, 'mod.wizards.form');
278  $settings = $modTSconfig['properties'];
279  $this->removeTrailingDotsFromTyposcript($settings);
280  $this->doc->JScode .= $this->doc->wrapScriptTags('TYPO3.Form.Wizard.Settings = ' . json_encode($settings) . ';');
281  }
282 
288  protected function loadLocalization()
289  {
290  $wizardLabels = $this->getLanguageService()->includeLLFile('EXT:form/Resources/Private/Language/locallang_wizard.xlf', false, true);
291  $controllerLabels = $this->getLanguageService()->includeLLFile('EXT:form/Resources/Private/Language/locallang.xlf', false, true);
292  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($controllerLabels, $wizardLabels);
293  $this->getPageRenderer()->addInlineLanguageLabelArray($controllerLabels['default']);
294  }
295 
304  protected function callRenderHook()
305  {
306  $params = array();
307  if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['form']['hooks']['renderWizard'])) {
308  foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['form']['hooks']['renderWizard'] as $funcRef) {
309  GeneralUtility::callUserFunction($funcRef, $params, $this);
310  }
311  }
312  }
313 
320  protected function removeTrailingDotsFromTyposcript(array &$array)
321  {
322  foreach ($array as $key => $value) {
323  if (is_array($value)) {
324  $this->removeTrailingDotsFromTyposcript($value);
325  }
326  if (substr($key, -1) === '.') {
327  $newKey = substr($key, 0, -1);
328  unset($array[$key]);
329  $array[$newKey] = $value;
330  }
331  }
332  }
333 
340  protected function getButtons()
341  {
343  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
344 
345  $buttons = array(
346  'csh' => '',
347  'csh_buttons' => '',
348  'close' => '',
349  'save' => '',
350  'save_close' => '',
351  'reload' => ''
352  );
353  // CSH
354  $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz');
355  // CSH Buttons
356  $buttons['csh_buttons'] = BackendUtility::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_buttons');
357  // Close
358  $getPostVariables = GeneralUtility::_GP('P');
359  $title = 'title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', true) . '"';
360  $onClick = htmlspecialchars('jumpToUrl(unescape(\'' .
361  rawurlencode(GeneralUtility::sanitizeLocalUrl($getPostVariables['returnUrl'])) . '\')); return false;');
362  $buttons['close'] = '<a href="#" onclick="' . $onClick . '" ' . $title . '>' .
363  $iconFactory->getIcon('actions-document-close', Icon::SIZE_SMALL)->render() . '</a>';
364  return $buttons;
365  }
366 
375  protected function getBodyContent()
376  {
377  if ($this->recordIsAvailable) {
378  $bodyContent = '';
379  } else {
381  $flashMessage = GeneralUtility::makeInstance(FlashMessage::class,
382  $this->getLanguageService()->getLL('errorMessage', true),
383  $this->getLanguageService()->getLL('errorTitle', true),
384  FlashMessage::ERROR);
385  $bodyContent = $flashMessage->render();
386  }
387  return $bodyContent;
388  }
389 
393  protected function getPageRenderer()
394  {
395  if (!isset($this->pageRenderer)) {
396  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
397  }
398 
399  return $this->pageRenderer;
400  }
401 
407  protected function getLanguageService()
408  {
409  return $GLOBALS['LANG'];
410  }
411 }