[BUGFIX] Fix RequireJS resolution in FormEngine 05/43505/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Wed, 23 Sep 2015 15:18:12 +0000 (17:18 +0200)
committerNicole Cordes <typo3@cordes.co>
Thu, 24 Sep 2015 10:13:57 +0000 (12:13 +0200)
The FormInlineAjaxController expects a different array structure
for RequireJS modules as FormResultCompiler does, which
is incompatible to each other.

Adopt the resolution of FormResultCompiler to fix JavaScript
errors and load modules properly.

Resolves: #69647
Releases: master
Change-Id: I2f2730e7c482dbc4722791b995a88c3c1138385a
Reviewed-on: http://review.typo3.org/43505
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
typo3/sysext/backend/Classes/Controller/FormInlineAjaxController.php

index 2356077..0167cfc 100644 (file)
@@ -439,19 +439,32 @@ class FormInlineAjaxController {
                        $jsonResult['scriptCall'][] = $singleAdditionalJavaScriptPost;
                }
                $jsonResult['scriptCall'][] = $childResult['extJSCODE'];
-               foreach ($childResult['requireJsModules'] as $moduleName => $callbacks) {
-                       if (!is_array($callbacks)) {
-                               $callbacks = array($callbacks);
-                       }
-                       foreach ($callbacks as $callback) {
-                               $inlineCodeKey = $moduleName;
-                               $javaScriptCode = 'require(["' . $moduleName . '"]';
-                               if ($callback !== NULL) {
-                                       $inlineCodeKey .= sha1($callback);
-                                       $javaScriptCode .= ', ' . $callback;
+               if (!empty($childResult['requireJsModules'])) {
+                       foreach ($childResult['requireJsModules'] as $module) {
+                               $moduleName = NULL;
+                               $callback = NULL;
+                               if (is_string($module)) {
+                                       // if $module is a string, no callback
+                                       $moduleName = $module;
+                                       $callback = NULL;
+                               } elseif (is_array($module)) {
+                                       // if $module is an array, callback is possible
+                                       foreach ($module as $key => $value) {
+                                               $moduleName = $key;
+                                               $callback = $value;
+                                               break;
+                                       }
+                               }
+                               if ($moduleName !== NULL) {
+                                       $inlineCodeKey = $moduleName;
+                                       $javaScriptCode = 'require(["' . $moduleName . '"]';
+                                       if ($callback !== NULL) {
+                                               $inlineCodeKey .= sha1($callback);
+                                               $javaScriptCode .= ', ' . $callback;
+                                       }
+                                       $javaScriptCode .= ');';
+                                       $jsonResult['scriptCall'][] = '/*RequireJS-Module-' . $inlineCodeKey . '*/' . LF . $javaScriptCode;
                                }
-                               $javaScriptCode .= ');';
-                               $jsonResult['scriptCall'][] = '/*RequireJS-Module-' . $inlineCodeKey . '*/' . LF . $javaScriptCode;
                        }
                }
                return $jsonResult;