[BUGFIX] Protect a forgotten AbstractFormEngineAjaxController method
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / AbstractFormEngineAjaxController.php
index 028ed08..ca960bb 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-declare(strict_types=1);
+declare(strict_types = 1);
 namespace TYPO3\CMS\Backend\Controller;
 
 /*
@@ -15,6 +15,11 @@ namespace TYPO3\CMS\Backend\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Localization\LocalizationFactory;
+use TYPO3\CMS\Core\Utility\ArrayUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
+
 /**
  * Abstract class for a couple of FormEngine controllers triggered by
  * ajax calls. The class containers some helpers to for instance prepare
@@ -31,7 +36,7 @@ abstract class AbstractFormEngineAjaxController
      * @param array $result
      * @return array
      */
-    public function createExecutableStringRepresentationOfRegisteredRequireJsModules(array $result): array
+    protected function createExecutableStringRepresentationOfRegisteredRequireJsModules(array $result): array
     {
         if (empty($result['requireJsModules'])) {
             return [];
@@ -65,4 +70,56 @@ abstract class AbstractFormEngineAjaxController
         }
         return $requireJs;
     }
+
+    /**
+     * Resolve a CSS file position, possibly prefixed with 'EXT:'
+     *
+     * @param string $stylesheetFile Given file, possibly prefixed with EXT:
+     * @return string Web root relative position to file
+     */
+    protected function getRelativePathToStylesheetFile(string $stylesheetFile): string
+    {
+        if (strpos($stylesheetFile, 'EXT:') === 0) {
+            $stylesheetFile = GeneralUtility::getFileAbsFileName($stylesheetFile);
+            $stylesheetFile = PathUtility::getRelativePathTo($stylesheetFile);
+            $stylesheetFile = rtrim($stylesheetFile, '/');
+        } else {
+            $stylesheetFile = GeneralUtility::resolveBackPath($stylesheetFile);
+        }
+        $stylesheetFile = GeneralUtility::createVersionNumberedFilename($stylesheetFile);
+        return PathUtility::getAbsoluteWebPath($stylesheetFile);
+    }
+
+    /**
+     * Parse a language file and get a label/value array from it.
+     *
+     * @param string $file EXT:path/to/file
+     * @return array Label/value array
+     */
+    protected function getLabelsFromLocalizationFile($file)
+    {
+        /** @var $languageFactory LocalizationFactory */
+        $languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);
+        $language = $GLOBALS['LANG']->lang;
+        $localizationArray = $languageFactory->getParsedData($file, $language);
+        if (is_array($localizationArray) && !empty($localizationArray)) {
+            if (!empty($localizationArray[$language])) {
+                $xlfLabelArray = $localizationArray['default'];
+                ArrayUtility::mergeRecursiveWithOverrule($xlfLabelArray, $localizationArray[$language], true, false);
+            } else {
+                $xlfLabelArray = $localizationArray['default'];
+            }
+        } else {
+            $xlfLabelArray = [];
+        }
+        $labelArray = [];
+        foreach ($xlfLabelArray as $key => $value) {
+            if (isset($value[0]['target'])) {
+                $labelArray[$key] = $value[0]['target'];
+            } else {
+                $labelArray[$key] = '';
+            }
+        }
+        return $labelArray;
+    }
 }