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