‪TYPO3CMS  10.4
FormResultCompiler.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
23 
30 {
34  protected ‪$hiddenFieldAccum = [];
35 
43  protected ‪$doSaveFieldName = '';
44 
48  protected ‪$inlineData = [];
49 
55  protected ‪$stylesheetFiles = [];
56 
62  protected ‪$additionalJavaScriptPost = [];
63 
70 
77  protected ‪$requireJsModules = [];
78 
82  protected ‪$pageRenderer;
83 
90  public function ‪mergeResult(array $resultArray)
91  {
92  $this->doSaveFieldName = $resultArray['doSaveFieldName'];
93  foreach ($resultArray['additionalJavaScriptPost'] as $element) {
94  $this->additionalJavaScriptPost[] = $element;
95  }
96  if (!empty($resultArray['requireJsModules'])) {
97  foreach ($resultArray['requireJsModules'] as $module) {
98  $moduleName = null;
99  $callback = null;
100  if (is_string($module)) {
101  // if $module is a string, no callback
102  $moduleName = $module;
103  $callback = null;
104  } elseif (is_array($module)) {
105  // if $module is an array, callback is possible
106  $callback = reset($module);
107  $moduleName = key($module);
108  }
109  if ($moduleName !== null) {
110  if (!empty($this->requireJsModules[$moduleName]) && $callback !== null) {
111  $existingValue = $this->requireJsModules[$moduleName];
112  if (!is_array($existingValue)) {
113  $existingValue = [$existingValue];
114  }
115  $existingValue[] = $callback;
116  $this->requireJsModules[$moduleName] = $existingValue;
117  } else {
118  $this->requireJsModules[$moduleName] = $callback;
119  }
120  }
121  }
122  }
123 
124  foreach ($resultArray['additionalHiddenFields'] as $element) {
125  $this->hiddenFieldAccum[] = $element;
126  }
127  foreach ($resultArray['stylesheetFiles'] as $stylesheetFile) {
128  if (!in_array($stylesheetFile, $this->stylesheetFiles)) {
129  $this->stylesheetFiles[] = $stylesheetFile;
130  }
131  }
132 
133  if (!empty($resultArray['inlineData'])) {
134  $resultArrayInlineData = ‪$this->inlineData;
135  $resultInlineData = $resultArray['inlineData'];
136  ‪ArrayUtility::mergeRecursiveWithOverrule($resultArrayInlineData, $resultInlineData);
137  $this->inlineData = $resultArrayInlineData;
138  }
139 
140  if (!empty($resultArray['additionalInlineLanguageLabelFiles'])) {
141  foreach ($resultArray['additionalInlineLanguageLabelFiles'] as $additionalInlineLanguageLabelFile) {
142  $this->additionalInlineLanguageLabelFiles[] = $additionalInlineLanguageLabelFile;
143  }
144  }
145  }
146 
152  public function ‪addCssFiles()
153  {
155  foreach ($this->stylesheetFiles as $stylesheetFile) {
156  ‪$pageRenderer->‪addCssFile($stylesheetFile);
157  }
158  return '';
159  }
160 
168  public function ‪printNeededJSFunctions()
169  {
170  // set variables to be accessible for JS
172  ‪$pageRenderer->‪addInlineSetting('FormEngine', 'formName', 'editform');
173 
174  return $this->‪JSbottom();
175  }
176 
182  protected function ‪JSbottom()
183  {
186  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
187 
188  // @todo: this is messy here - "additional hidden fields" should be handled elsewhere
189  $html = implode(LF, $this->hiddenFieldAccum);
190  ‪$pageRenderer->‪addJsFile('EXT:backend/Resources/Public/JavaScript/md5.js');
191  // load the main module for FormEngine with all important JS functions
192  if (!is_array($this->requireJsModules['TYPO3/CMS/Backend/FormEngine'] ?? null)) {
193  $this->requireJsModules['TYPO3/CMS/Backend/FormEngine'] = [$this->requireJsModules['TYPO3/CMS/Backend/FormEngine']];
194  }
195  $this->requireJsModules['TYPO3/CMS/Backend/FormEngine'][] = 'function(FormEngine) {
196  FormEngine.initialize(
197  ' . GeneralUtility::quoteJSvalue((string)$uriBuilder->buildUriFromRoute('wizard_element_browser')) . ',
198  ' . (‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? '1' : '0') . '
199  );
200  }';
201  $this->requireJsModules['TYPO3/CMS/Backend/FormEngineReview'] = null;
202 
203  foreach ($this->requireJsModules as $moduleName => $callbacks) {
204  if (!is_array($callbacks)) {
205  $callbacks = [$callbacks];
206  }
207  foreach ($callbacks as $callback) {
208  ‪$pageRenderer->‪loadRequireJsModule($moduleName, $callback);
209  }
210  }
211  $backendUser = $this->‪getBackendUserAuthentication();
212 
213  // Make textareas resizable and flexible ("autogrow" in height)
214  $textareaSettings = [
215  'autosize' => (bool)$backendUser->uc['resizeTextareas_Flexible'],
216  ];
217  ‪$pageRenderer->‪addInlineSettingArray('Textarea', $textareaSettings);
218 
219  ‪$pageRenderer->‪addJsFile('EXT:backend/Resources/Public/JavaScript/jsfunc.tbe_editor.js');
220  // Needed for FormEngine manipulation (date picker)
221  $dateFormat = (‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? ['MM-DD-YYYY', 'HH:mm MM-DD-YYYY'] : ['DD-MM-YYYY', 'HH:mm DD-MM-YYYY']);
222  ‪$pageRenderer->‪addInlineSetting('DateTimePicker', 'DateFormat', $dateFormat);
223 
224  ‪$pageRenderer->‪addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/locallang_core.xlf', 'file_upload');
225  if (!empty($this->additionalInlineLanguageLabelFiles)) {
226  foreach ($this->additionalInlineLanguageLabelFiles as $additionalInlineLanguageLabelFile) {
227  ‪$pageRenderer->‪addInlineLanguageLabelFile($additionalInlineLanguageLabelFile);
228  }
229  }
230 
231  // todo: change these things in JS
233  'FormEngine.noRecordTitle' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.no_title'),
234  'FormEngine.fieldsChanged' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.fieldsChanged'),
235  'FormEngine.fieldsMissing' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.fieldsMissing'),
236  'FormEngine.maxItemsAllowed' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.maxItemsAllowed'),
237  'FormEngine.refreshRequiredTitle' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:mess.refreshRequired.title'),
238  'FormEngine.refreshRequiredContent' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:mess.refreshRequired.content'),
239  'FormEngine.remainingCharacters' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.remainingCharacters'),
240  ]);
241 
242  // Add JS required for inline fields
243  if (!empty($this->inlineData)) {
244  ‪$pageRenderer->‪addInlineSettingArray('FormEngineInline', $this->inlineData);
245  }
246  $out = LF . implode(LF, $this->additionalJavaScriptPost);
247 
248  return $html . LF . "\t" . GeneralUtility::wrapJS($out);
249  }
250 
254  protected function ‪getBackendUserAuthentication()
255  {
256  return ‪$GLOBALS['BE_USER'];
257  }
258 
264  protected function ‪getLanguageService()
265  {
266  return ‪$GLOBALS['LANG'];
267  }
268 
274  protected function ‪getPageRenderer()
275  {
276  if ($this->pageRenderer === null) {
277  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
278  }
279  return ‪$this->pageRenderer;
280  }
281 }
‪TYPO3\CMS\Backend\Form\FormResultCompiler\$inlineData
‪array $inlineData
Definition: FormResultCompiler.php:45
‪TYPO3\CMS\Core\Page\PageRenderer\addInlineLanguageLabelFile
‪addInlineLanguageLabelFile($fileRef, $selectionPrefix='', $stripFromSelectionName='')
Definition: PageRenderer.php:1564
‪TYPO3\CMS\Backend\Form\FormResultCompiler\getPageRenderer
‪TYPO3 CMS Core Page PageRenderer getPageRenderer()
Definition: FormResultCompiler.php:266
‪TYPO3\CMS\Backend\Form\FormResultCompiler
Definition: FormResultCompiler.php:30
‪TYPO3\CMS\Backend\Form\FormResultCompiler\$additionalInlineLanguageLabelFiles
‪array $additionalInlineLanguageLabelFiles
Definition: FormResultCompiler.php:63
‪TYPO3\CMS\Backend\Form
Definition: AbstractNode.php:18
‪TYPO3\CMS\Backend\Form\FormResultCompiler\JSbottom
‪string JSbottom()
Definition: FormResultCompiler.php:174
‪TYPO3\CMS\Backend\Form\FormResultCompiler\mergeResult
‪mergeResult(array $resultArray)
Definition: FormResultCompiler.php:82
‪TYPO3\CMS\Backend\Form\FormResultCompiler\getLanguageService
‪TYPO3 CMS Core Localization LanguageService getLanguageService()
Definition: FormResultCompiler.php:256
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:654
‪TYPO3\CMS\Core\Page\PageRenderer\loadRequireJsModule
‪loadRequireJsModule($mainModuleName, $callBackFunction=null)
Definition: PageRenderer.php:1493
‪TYPO3\CMS\Core\Page\PageRenderer\addInlineSettingArray
‪addInlineSettingArray($namespace, array $array)
Definition: PageRenderer.php:1610
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:42
‪TYPO3\CMS\Core\Page\PageRenderer\addCssFile
‪addCssFile($file, $rel='stylesheet', $media='all', $title='', $compress=true, $forceOnTop=false, $allWrap='', $excludeFromConcatenation=false, $splitChar='|', $inline=false)
Definition: PageRenderer.php:1201
‪TYPO3\CMS\Backend\Form\FormResultCompiler\addCssFiles
‪string addCssFiles()
Definition: FormResultCompiler.php:144
‪TYPO3\CMS\Backend\Form\FormResultCompiler\$stylesheetFiles
‪array $stylesheetFiles
Definition: FormResultCompiler.php:51
‪TYPO3\CMS\Backend\Form\FormResultCompiler\$hiddenFieldAccum
‪array $hiddenFieldAccum
Definition: FormResultCompiler.php:33
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Core\Page\PageRenderer\addInlineLanguageLabelArray
‪addInlineLanguageLabelArray(array $array)
Definition: PageRenderer.php:1552
‪TYPO3\CMS\Backend\Form\FormResultCompiler\$doSaveFieldName
‪string $doSaveFieldName
Definition: FormResultCompiler.php:41
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Form\FormResultCompiler\$requireJsModules
‪array $requireJsModules
Definition: FormResultCompiler.php:70
‪TYPO3\CMS\Backend\Form\FormResultCompiler\$additionalJavaScriptPost
‪array $additionalJavaScriptPost
Definition: FormResultCompiler.php:57
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Page\PageRenderer\addJsFile
‪addJsFile($file, $type='text/javascript', $compress=true, $forceOnTop=false, $allWrap='', $excludeFromConcatenation=false, $splitChar='|', $async=false, $integrity='', $defer=false, $crossorigin='', $nomodule=false)
Definition: PageRenderer.php:1089
‪TYPO3\CMS\Core\Page\PageRenderer\addInlineSetting
‪addInlineSetting($namespace, $key, $value)
Definition: PageRenderer.php:1584
‪TYPO3\CMS\Backend\Form\FormResultCompiler\$pageRenderer
‪PageRenderer $pageRenderer
Definition: FormResultCompiler.php:74
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Form\FormResultCompiler\printNeededJSFunctions
‪string printNeededJSFunctions()
Definition: FormResultCompiler.php:160
‪TYPO3\CMS\Backend\Form\FormResultCompiler\getBackendUserAuthentication
‪BackendUserAuthentication getBackendUserAuthentication()
Definition: FormResultCompiler.php:246