TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
FormResultCompiler.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Form;
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 
23 
30 {
34  protected $extJSCODE = '';
35 
39  protected $hiddenFieldAccum = [];
40 
48  protected $doSaveFieldName = '';
49 
53  protected $inlineData = [];
54 
60  protected $stylesheetFiles = [];
61 
67  protected $additionalJS_post = [];
68 
75  protected $additionalJS_submit = [];
76 
83 
90  protected $requireJsModules = [];
91 
95  protected $pageRenderer = null;
96 
104  public function mergeResult(array $resultArray)
105  {
106  $this->doSaveFieldName = $resultArray['doSaveFieldName'];
107  foreach ($resultArray['additionalJavaScriptPost'] as $element) {
108  $this->additionalJS_post[] = $element;
109  }
110  foreach ($resultArray['additionalJavaScriptSubmit'] as $element) {
111  $this->additionalJS_submit[] = $element;
112  }
113  if (!empty($resultArray['requireJsModules'])) {
114  foreach ($resultArray['requireJsModules'] as $module) {
115  $moduleName = null;
116  $callback = null;
117  if (is_string($module)) {
118  // if $module is a string, no callback
119  $moduleName = $module;
120  $callback = null;
121  } elseif (is_array($module)) {
122  // if $module is an array, callback is possible
123  foreach ($module as $key => $value) {
124  $moduleName = $key;
125  $callback = $value;
126  break;
127  }
128  }
129  if ($moduleName !== null) {
130  if (!empty($this->requireJsModules[$moduleName]) && $callback !== null) {
131  $existingValue = $this->requireJsModules[$moduleName];
132  if (!is_array($existingValue)) {
133  $existingValue = [$existingValue];
134  }
135  $existingValue[] = $callback;
136  $this->requireJsModules[$moduleName] = $existingValue;
137  } else {
138  $this->requireJsModules[$moduleName] = $callback;
139  }
140  }
141  }
142  }
143  $this->extJSCODE = $this->extJSCODE . LF . $resultArray['extJSCODE'];
144  $this->inlineData = $resultArray['inlineData'];
145  foreach ($resultArray['additionalHiddenFields'] as $element) {
146  $this->hiddenFieldAccum[] = $element;
147  }
148  foreach ($resultArray['stylesheetFiles'] as $stylesheetFile) {
149  if (!in_array($stylesheetFile, $this->stylesheetFiles)) {
150  $this->stylesheetFiles[] = $stylesheetFile;
151  }
152  }
153 
154  if (!empty($resultArray['inlineData'])) {
155  $resultArrayInlineData = $this->inlineData;
156  $resultInlineData = $resultArray['inlineData'];
157  ArrayUtility::mergeRecursiveWithOverrule($resultArrayInlineData, $resultInlineData);
158  $this->inlineData = $resultArrayInlineData;
159  }
160 
161  if (!empty($resultArray['additionalInlineLanguageLabelFiles'])) {
162  foreach ($resultArray['additionalInlineLanguageLabelFiles'] as $additionalInlineLanguageLabelFile) {
163  $this->additionalInlineLanguageLabelFiles[] = $additionalInlineLanguageLabelFile;
164  }
165  }
166  }
167 
174  public function JStop()
175  {
177  return $this->addCssFiles();
178  }
179 
185  public function addCssFiles()
186  {
187  $pageRenderer = $this->getPageRenderer();
188  foreach ($this->stylesheetFiles as $stylesheetFile) {
189  $pageRenderer->addCssFile($stylesheetFile);
190  }
191  return '';
192  }
193 
201  public function printNeededJSFunctions()
202  {
203  // set variables to be accessible for JS
204  $pageRenderer = $this->getPageRenderer();
205  $pageRenderer->addInlineSetting('FormEngine', 'formName', 'editform');
206 
207  return $this->JSbottom();
208  }
209 
215  protected function JSbottom()
216  {
217  $pageRenderer = $this->getPageRenderer();
218 
219  // @todo: this is messy here - "additional hidden fields" should be handled elsewhere
220  $html = implode(LF, $this->hiddenFieldAccum);
221  $pageRenderer->addJsFile('EXT:backend/Resources/Public/JavaScript/md5.js');
222  // load the main module for FormEngine with all important JS functions
223  $this->requireJsModules['TYPO3/CMS/Backend/FormEngine'] = 'function(FormEngine) {
224  FormEngine.setBrowserUrl(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('wizard_element_browser')) . ');
225  }';
226  $this->requireJsModules['TYPO3/CMS/Backend/FormEngineValidation'] = 'function(FormEngineValidation) {
227  FormEngineValidation.setUsMode(' . ($GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? '1' : '0') . ');
228  FormEngineValidation.registerReady();
229  }';
230 
231  foreach ($this->requireJsModules as $moduleName => $callbacks) {
232  if (!is_array($callbacks)) {
233  $callbacks = [$callbacks];
234  }
235  foreach ($callbacks as $callback) {
236  $pageRenderer->loadRequireJsModule($moduleName, $callback);
237  }
238  }
239  $pageRenderer->loadJquery();
240  $pageRenderer->loadExtJS();
241  $beUserAuth = $this->getBackendUserAuthentication();
242 
243  // define the window size of the element browser etc.
244  $popupWindowWidth = 700;
245  $popupWindowHeight = 750;
246  $popupWindowSize = trim($beUserAuth->getTSConfigVal('options.popupWindowSize'));
247  if (!empty($popupWindowSize)) {
248  list($popupWindowWidth, $popupWindowHeight) = GeneralUtility::intExplode('x', $popupWindowSize);
249  }
250 
251  // define the window size of the popups within the RTE
252  $rtePopupWindowSize = trim($beUserAuth->getTSConfigVal('options.rte.popupWindowSize'));
253  if (!empty($rtePopupWindowSize)) {
254  list($rtePopupWindowWidth, $rtePopupWindowHeight) = GeneralUtility::trimExplode('x', $rtePopupWindowSize);
255  }
256  $rtePopupWindowWidth = !empty($rtePopupWindowWidth) ? (int)$rtePopupWindowWidth : ($popupWindowWidth-100);
257  $rtePopupWindowHeight = !empty($rtePopupWindowHeight) ? (int)$rtePopupWindowHeight : ($popupWindowHeight-150);
258 
259  // Make textareas resizable and flexible ("autogrow" in height)
260  $textareaSettings = [
261  'autosize' => (bool)$beUserAuth->uc['resizeTextareas_Flexible'],
262  'RTEPopupWindow' => [
263  'width' => $rtePopupWindowWidth,
264  'height' => $rtePopupWindowHeight
265  ]
266  ];
267  $pageRenderer->addInlineSettingArray('Textarea', $textareaSettings);
268 
269  $popupSettings = [
270  'PopupWindow' => [
271  'width' => $popupWindowWidth,
272  'height' => $popupWindowHeight
273  ]
274  ];
275  $pageRenderer->addInlineSettingArray('Popup', $popupSettings);
276 
277  $pageRenderer->addJsFile('EXT:backend/Resources/Public/JavaScript/jsfunc.tbe_editor.js');
278  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ValueSlider');
279  // Needed for FormEngine manipulation (date picker)
280  $dateFormat = ($GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? ['MM-DD-YYYY', 'HH:mm MM-DD-YYYY'] : ['DD-MM-YYYY', 'HH:mm DD-MM-YYYY']);
281  $pageRenderer->addInlineSetting('DateTimePicker', 'DateFormat', $dateFormat);
282 
283  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Filelist/FileListLocalisation');
284 
285  $pageRenderer->addInlineLanguageLabelFile('EXT:lang/Resources/Private/Language/locallang_core.xlf', 'file_upload');
286  if (!empty($this->additionalInlineLanguageLabelFiles)) {
287  foreach ($this->additionalInlineLanguageLabelFiles as $additionalInlineLanguageLabelFile) {
288  $pageRenderer->addInlineLanguageLabelFile($additionalInlineLanguageLabelFile);
289  }
290  }
291  // Load codemirror for T3Editor
292  if (ExtensionManagementUtility::isLoaded('t3editor')) {
293  $pageRenderer->addJsFile('EXT:t3editor/Resources/Public/JavaScript/Contrib/codemirror/js/codemirror.js');
294  }
295  // We want to load jQuery-ui inside our js. Enable this using requirejs.
296  $pageRenderer->addJsFile('EXT:backend/Resources/Public/JavaScript/jsfunc.inline.js');
297 
298  // todo: change these things in JS
299  $pageRenderer->addInlineLanguageLabelArray([
300  'FormEngine.noRecordTitle' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.no_title',
301  'FormEngine.fieldsChanged' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.fieldsChanged',
302  'FormEngine.fieldsMissing' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.fieldsMissing',
303  'FormEngine.maxItemsAllowed' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.maxItemsAllowed',
304  'FormEngine.refreshRequiredTitle' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:mess.refreshRequired.title',
305  'FormEngine.refreshRequiredContent' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:mess.refreshRequired.content',
306  'FormEngine.remainingCharacters' => 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.remainingCharacters',
307  ], true);
308 
309  $out = '
310  TBE_EDITOR.doSaveFieldName = "' . ($this->doSaveFieldName ? addslashes($this->doSaveFieldName) : '') . '";
311  ';
312 
313  // Add JS required for inline fields
314  if (!empty($this->inlineData)) {
315  $out .= '
316  inline.addToDataArray(' . json_encode($this->inlineData) . ');
317  ';
318  }
319  // $this->additionalJS_submit:
320  if ($this->additionalJS_submit) {
321  $additionalJS_submit = implode('', $this->additionalJS_submit);
322  $additionalJS_submit = str_replace([CR, LF], '', $additionalJS_submit);
323  $out .= '
324  TBE_EDITOR.addActionChecks("submit", "' . addslashes($additionalJS_submit) . '");
325  ';
326  }
327  $out .= LF . implode(LF, $this->additionalJS_post) . LF . $this->extJSCODE;
328 
329  return $html . LF . TAB . GeneralUtility::wrapJS($out);
330  }
331 
335  protected function getBackendUserAuthentication()
336  {
337  return $GLOBALS['BE_USER'];
338  }
339 
345  protected function getPageRenderer()
346  {
347  if ($this->pageRenderer === null) {
348  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
349  }
350  return $this->pageRenderer;
351  }
352 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
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']
static makeInstance($className,...$constructorArguments)
static intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)