‪TYPO3CMS  ‪main
FormResultCompiler.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
27 
34 {
38  protected ‪$hiddenFieldAccum = [];
39 
47  protected ‪$doSaveFieldName = '';
48 
52  protected ‪$inlineData = [];
53 
59  protected ‪$stylesheetFiles = [];
60 
67 
73  protected ‪$javaScriptModules = [];
74 
78  protected ‪$pageRenderer;
79 
86  public function ‪mergeResult(array $resultArray)
87  {
88  $this->doSaveFieldName = $resultArray['doSaveFieldName'] ?? '';
89  foreach ($resultArray['javaScriptModules'] ?? [] as $module) {
90  if (!$module instanceof ‪JavaScriptModuleInstruction) {
91  throw new \LogicException(
92  sprintf(
93  'Module must be a %s, type "%s" given',
94  JavaScriptModuleInstruction::class,
95  gettype($module)
96  ),
97  1663860283
98  );
99  }
100  $this->javaScriptModules[] = $module;
101  }
102  foreach ($resultArray['additionalHiddenFields'] as $element) {
103  $this->hiddenFieldAccum[] = $element;
104  }
105  foreach ($resultArray['stylesheetFiles'] as $stylesheetFile) {
106  if (!in_array($stylesheetFile, $this->stylesheetFiles)) {
107  $this->stylesheetFiles[] = $stylesheetFile;
108  }
109  }
110 
111  if (!empty($resultArray['inlineData'])) {
112  $resultArrayInlineData = ‪$this->inlineData;
113  $resultInlineData = $resultArray['inlineData'];
114  ArrayUtility::mergeRecursiveWithOverrule($resultArrayInlineData, $resultInlineData);
115  $this->inlineData = $resultArrayInlineData;
116  }
117 
118  if (!empty($resultArray['additionalInlineLanguageLabelFiles'])) {
119  foreach ($resultArray['additionalInlineLanguageLabelFiles'] as $additionalInlineLanguageLabelFile) {
120  $this->additionalInlineLanguageLabelFiles[] = $additionalInlineLanguageLabelFile;
121  }
122  }
123  }
124 
130  public function ‪addCssFiles()
131  {
133  foreach ($this->stylesheetFiles as $stylesheetFile) {
134  ‪$pageRenderer->‪addCssFile($stylesheetFile);
135  }
136  return '';
137  }
138 
146  public function ‪printNeededJSFunctions()
147  {
148  // set variables to be accessible for JS
150  ‪$pageRenderer->‪addInlineSetting('FormEngine', 'formName', 'editform');
151 
152  return $this->‪JSbottom();
153  }
154 
160  protected function ‪JSbottom()
161  {
163  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
164 
165  // @todo: this is messy here - "additional hidden fields" should be handled elsewhere
166  $html = implode(LF, $this->hiddenFieldAccum);
167  // load the main module for FormEngine with all important JS functions
168  $this->javaScriptModules[] = ‪JavaScriptModuleInstruction::create('@typo3/backend/form-engine.js')
169  ->invoke(
170  'initialize',
171  (string)$uriBuilder->buildUriFromRoute('wizard_element_browser')
172  );
173  $this->javaScriptModules[] = ‪JavaScriptModuleInstruction::create('@typo3/backend/form-engine-review.js');
174 
175  foreach ($this->javaScriptModules as $module) {
176  ‪$pageRenderer->‪getJavaScriptRenderer()->addJavaScriptModuleInstruction($module);
177  }
178 
179  // Needed for FormEngine manipulation (date picker)
180  $dateFormat = ['dd-MM-yyyy', 'HH:mm dd-MM-yyyy'];
181  ‪$pageRenderer->‪addInlineSetting('DateTimePicker', 'DateFormat', $dateFormat);
182 
183  ‪$pageRenderer->‪addInlineLanguageLabelFile('EXT:core/Resources/Private/Language/locallang_core.xlf', 'file_upload');
184  ‪$pageRenderer->‪addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf');
185  if (!empty($this->additionalInlineLanguageLabelFiles)) {
186  foreach ($this->additionalInlineLanguageLabelFiles as $additionalInlineLanguageLabelFile) {
187  ‪$pageRenderer->‪addInlineLanguageLabelFile($additionalInlineLanguageLabelFile);
188  }
189  }
190 
191  ‪$pageRenderer->‪loadJavaScriptModule('@typo3/backend/form-engine/request-update.js');
192 
193  // todo: change these things in JS
195  'FormEngine.noRecordTitle' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.no_title'),
196  'FormEngine.fieldsChanged' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.fieldsChanged'),
197  'FormEngine.fieldsMissing' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.fieldsMissing'),
198  'FormEngine.maxItemsAllowed' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.maxItemsAllowed'),
199  'FormEngine.refreshRequiredTitle' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:mess.refreshRequired.title'),
200  'FormEngine.refreshRequiredContent' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:mess.refreshRequired.content'),
201  'FormEngine.remainingCharacters' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.remainingCharacters'),
202  'FormEngine.minCharactersLeft' => $this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.minCharactersLeft'),
203  'label.confirm.delete_record.content' => $this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf:label.confirm.delete_record.content'),
204  'label.confirm.delete_record.title' => $this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf:label.confirm.delete_record.title'),
205  'buttons.confirm.delete_record.no' => $this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf:buttons.confirm.delete_record.no'),
206  'buttons.confirm.delete_record.yes' => $this->‪getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf:buttons.confirm.delete_record.yes'),
207  ]);
208 
209  // Add JS required for inline fields
210  if (!empty($this->inlineData)) {
211  ‪$pageRenderer->‪addInlineSettingArray('FormEngineInline', $this->inlineData);
212  }
213 
214  return $html;
215  }
216 
218  {
219  return ‪$GLOBALS['BE_USER'];
220  }
221 
222  protected function ‪getLanguageService(): LanguageService
223  {
224  return ‪$GLOBALS['LANG'];
225  }
226 
232  protected function ‪getPageRenderer()
233  {
234  if ($this->pageRenderer === null) {
235  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
236  }
237  return ‪$this->pageRenderer;
238  }
239 }
‪TYPO3\CMS\Backend\Form\FormResultCompiler\$inlineData
‪array $inlineData
Definition: FormResultCompiler.php:49
‪TYPO3\CMS\Core\Page\PageRenderer\addInlineLanguageLabelFile
‪addInlineLanguageLabelFile($fileRef, $selectionPrefix='', $stripFromSelectionName='')
Definition: PageRenderer.php:1057
‪TYPO3\CMS\Backend\Form\FormResultCompiler\getPageRenderer
‪TYPO3 CMS Core Page PageRenderer getPageRenderer()
Definition: FormResultCompiler.php:225
‪TYPO3\CMS\Backend\Form\FormResultCompiler
Definition: FormResultCompiler.php:34
‪TYPO3\CMS\Backend\Form\FormResultCompiler\$additionalInlineLanguageLabelFiles
‪array $additionalInlineLanguageLabelFiles
Definition: FormResultCompiler.php:61
‪TYPO3\CMS\Backend\Form
Definition: AbstractNode.php:18
‪TYPO3\CMS\Backend\Form\FormResultCompiler\JSbottom
‪string JSbottom()
Definition: FormResultCompiler.php:153
‪TYPO3\CMS\Backend\Form\FormResultCompiler\mergeResult
‪mergeResult(array $resultArray)
Definition: FormResultCompiler.php:79
‪TYPO3\CMS\Core\Page\PageRenderer\getJavaScriptRenderer
‪getJavaScriptRenderer()
Definition: PageRenderer.php:208
‪TYPO3\CMS\Backend\Form\FormResultCompiler\$javaScriptModules
‪list< JavaScriptModuleInstruction > $javaScriptModules
Definition: FormResultCompiler.php:67
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction\create
‪static create(string $name, string $exportName=null)
Definition: JavaScriptModuleInstruction.php:47
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction
Definition: JavaScriptModuleInstruction.php:23
‪TYPO3\CMS\Core\Page\PageRenderer\addInlineSettingArray
‪addInlineSettingArray($namespace, array $array)
Definition: PageRenderer.php:1102
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:44
‪TYPO3\CMS\Backend\Form\FormResultCompiler\addCssFiles
‪string addCssFiles()
Definition: FormResultCompiler.php:123
‪TYPO3\CMS\Backend\Form\FormResultCompiler\$stylesheetFiles
‪array $stylesheetFiles
Definition: FormResultCompiler.php:55
‪TYPO3\CMS\Backend\Form\FormResultCompiler\$hiddenFieldAccum
‪array $hiddenFieldAccum
Definition: FormResultCompiler.php:37
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Core\Page\PageRenderer\addInlineLanguageLabelArray
‪addInlineLanguageLabelArray(array $array)
Definition: PageRenderer.php:1045
‪TYPO3\CMS\Backend\Form\FormResultCompiler\$doSaveFieldName
‪string $doSaveFieldName
Definition: FormResultCompiler.php:45
‪TYPO3\CMS\Core\Page\PageRenderer\addCssFile
‪addCssFile($file, $rel='stylesheet', $media='all', $title='', $compress=true, $forceOnTop=false, $allWrap='', $excludeFromConcatenation=false, $splitChar='|', $inline=false, array $tagAttributes=[])
Definition: PageRenderer.php:942
‪TYPO3\CMS\Backend\Form\FormResultCompiler\getBackendUserAuthentication
‪getBackendUserAuthentication()
Definition: FormResultCompiler.php:210
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Page\PageRenderer\loadJavaScriptModule
‪loadJavaScriptModule(string $specifier)
Definition: PageRenderer.php:1021
‪TYPO3\CMS\Backend\Form\FormResultCompiler\getLanguageService
‪getLanguageService()
Definition: FormResultCompiler.php:215
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Page\PageRenderer\addInlineSetting
‪addInlineSetting($namespace, $key, $value)
Definition: PageRenderer.php:1077
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Backend\Form\FormResultCompiler\$pageRenderer
‪PageRenderer $pageRenderer
Definition: FormResultCompiler.php:71
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Form\FormResultCompiler\printNeededJSFunctions
‪string printNeededJSFunctions()
Definition: FormResultCompiler.php:139