‪TYPO3CMS  10.4
AbstractFormEngineAjaxController.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 
25 
34 {
43  {
44  if (empty($result['requireJsModules'])) {
45  return [];
46  }
47  $requireJs = [];
48  foreach ($result['requireJsModules'] as $module) {
49  $moduleName = null;
50  $callback = null;
51  if (is_string($module)) {
52  // if $module is a string, no callback
53  $moduleName = $module;
54  $callback = null;
55  } elseif (is_array($module)) {
56  // if $module is an array, callback is possible
57  $callback = reset($module);
58  $moduleName = key($module);
59  }
60  if ($moduleName !== null) {
61  $inlineCodeKey = $moduleName;
62  $javaScriptCode = 'require(["' . $moduleName . '"]';
63  if ($callback !== null) {
64  $inlineCodeKey .= sha1($callback);
65  $javaScriptCode .= ', ' . $callback;
66  }
67  $javaScriptCode .= ');';
68  $requireJs[] = '/*RequireJS-Module-' . $inlineCodeKey . '*/' . LF . $javaScriptCode;
69  }
70  }
71  return $requireJs;
72  }
73 
80  protected function ‪getRelativePathToStylesheetFile(string $stylesheetFile): string
81  {
82  if (strpos($stylesheetFile, 'EXT:') === 0) {
83  $stylesheetFile = GeneralUtility::getFileAbsFileName($stylesheetFile);
84  $stylesheetFile = ‪PathUtility::getRelativePathTo($stylesheetFile) ?? '';
85  $stylesheetFile = rtrim($stylesheetFile, '/');
86  } else {
87  $stylesheetFile = GeneralUtility::resolveBackPath($stylesheetFile);
88  }
89  $stylesheetFile = GeneralUtility::createVersionNumberedFilename($stylesheetFile);
90  return ‪PathUtility::getAbsoluteWebPath($stylesheetFile);
91  }
92 
99  protected function ‪getLabelsFromLocalizationFile($file)
100  {
102  $languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);
103  $language = $this->‪getLanguageService()->lang;
104  $localizationArray = $languageFactory->getParsedData($file, $language);
105  if (is_array($localizationArray) && !empty($localizationArray)) {
106  if (!empty($localizationArray[$language])) {
107  $xlfLabelArray = $localizationArray['default'];
108  ‪ArrayUtility::mergeRecursiveWithOverrule($xlfLabelArray, $localizationArray[$language], true, false);
109  } else {
110  $xlfLabelArray = $localizationArray['default'];
111  }
112  } else {
113  $xlfLabelArray = [];
114  }
115  $labelArray = [];
116  foreach ($xlfLabelArray as $key => $value) {
117  if (isset($value[0]['target'])) {
118  $labelArray[$key] = $value[0]['target'];
119  } else {
120  $labelArray[$key] = '';
121  }
122  }
123  return $labelArray;
124  }
125 
130  {
131  return ‪$GLOBALS['LANG'] ?? null;
132  }
133 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:24
‪TYPO3\CMS\Core\Localization\LocalizationFactory
Definition: LocalizationFactory.php:28
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:654
‪TYPO3\CMS\Backend\Controller\AbstractFormEngineAjaxController\createExecutableStringRepresentationOfRegisteredRequireJsModules
‪array createExecutableStringRepresentationOfRegisteredRequireJsModules(array $result)
Definition: AbstractFormEngineAjaxController.php:42
‪TYPO3\CMS\Core\Utility\PathUtility\getRelativePathTo
‪static string null getRelativePathTo($targetPath)
Definition: PathUtility.php:32
‪TYPO3\CMS\Backend\Controller\AbstractFormEngineAjaxController\getRelativePathToStylesheetFile
‪string getRelativePathToStylesheetFile(string $stylesheetFile)
Definition: AbstractFormEngineAjaxController.php:80
‪TYPO3\CMS\Backend\Controller\AbstractFormEngineAjaxController\getLabelsFromLocalizationFile
‪array getLabelsFromLocalizationFile($file)
Definition: AbstractFormEngineAjaxController.php:99
‪TYPO3\CMS\Backend\Controller\AbstractFormEngineAjaxController\getLanguageService
‪LanguageService null getLanguageService()
Definition: AbstractFormEngineAjaxController.php:129
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Controller\AbstractFormEngineAjaxController
Definition: AbstractFormEngineAjaxController.php:34
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:43
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:18