‪TYPO3CMS  9.5
AbstractFormEngineAjaxController.php
Go to the documentation of this file.
1 <?php
2 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 
22 
31 {
40  {
41  if (empty($result['requireJsModules'])) {
42  return [];
43  }
44  $requireJs = [];
45  foreach ($result['requireJsModules'] as $module) {
46  $moduleName = null;
47  $callback = null;
48  if (is_string($module)) {
49  // if $module is a string, no callback
50  $moduleName = $module;
51  $callback = null;
52  } elseif (is_array($module)) {
53  // if $module is an array, callback is possible
54  foreach ($module as $key => $value) {
55  $moduleName = $key;
56  $callback = $value;
57  break;
58  }
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 = ‪$GLOBALS['LANG']->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 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:23
‪TYPO3\CMS\Core\Localization\LocalizationFactory
Definition: LocalizationFactory.php:25
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Backend\Controller\AbstractFormEngineAjaxController\createExecutableStringRepresentationOfRegisteredRequireJsModules
‪array createExecutableStringRepresentationOfRegisteredRequireJsModules(array $result)
Definition: AbstractFormEngineAjaxController.php:39
‪TYPO3\CMS\Core\Utility\PathUtility\getRelativePathTo
‪static string null getRelativePathTo($targetPath)
Definition: PathUtility.php:31
‪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\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Controller\AbstractFormEngineAjaxController
Definition: AbstractFormEngineAjaxController.php:31
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:42
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:3