[BUGFIX] Make sure that foreach loops are applied to arrays only 85/55085/2
authorWolfgang Klinger <wolfgang@wazum.com>
Thu, 14 Dec 2017 10:33:53 +0000 (11:33 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 14 Dec 2017 20:41:29 +0000 (21:41 +0100)
Fix some foreach loops so as not to run into potentially empty elements.
Use the ?? operator to accomplish that.

Change-Id: Id6306cea0546dfd4a20ba98c170335966cc2ae40
Resolves: #83322
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/55085
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Form/AbstractNode.php

index a4116aa..6db48f3 100644 (file)
@@ -104,7 +104,9 @@ abstract class AbstractNode implements NodeInterface
     }
 
     /**
-     * Merge existing data with a child return array
+     * Merge existing data with a child return array.
+     * The incoming $childReturn array should be initialized
+     * using initializeResultArray() beforehand.
      *
      * @param array $existing Currently merged array
      * @param array $childReturn Array returned by child
@@ -121,27 +123,23 @@ abstract class AbstractNode implements NodeInterface
             GeneralUtility::logDeprecatedFunction();
             $existing['extJSCODE'] .= LF . $childReturn['extJSCODE'];
         }
-        foreach ($childReturn['additionalJavaScriptPost'] as $value) {
+        foreach ($childReturn['additionalJavaScriptPost'] ?? [] as $value) {
             $existing['additionalJavaScriptPost'][] = $value;
         }
-        foreach ($childReturn['additionalJavaScriptSubmit'] as $value) {
+        foreach ($childReturn['additionalJavaScriptSubmit'] ?? [] as $value) {
             $existing['additionalJavaScriptSubmit'][] = $value;
         }
-        foreach ($childReturn['additionalHiddenFields'] as $value) {
+        foreach ($childReturn['additionalHiddenFields'] ?? [] as $value) {
             $existing['additionalHiddenFields'][] = $value;
         }
-        foreach ($childReturn['stylesheetFiles'] as $value) {
+        foreach ($childReturn['stylesheetFiles'] ?? [] as $value) {
             $existing['stylesheetFiles'][] = $value;
         }
-        if (!empty($childReturn['requireJsModules'])) {
-            foreach ($childReturn['requireJsModules'] as $module) {
-                $existing['requireJsModules'][] = $module;
-            }
+        foreach ($childReturn['requireJsModules'] ?? [] as $module) {
+            $existing['requireJsModules'][] = $module;
         }
-        if (!empty($childReturn['additionalInlineLanguageLabelFiles'])) {
-            foreach ($childReturn['additionalInlineLanguageLabelFiles'] as $inlineLanguageLabelFile) {
-                $existing['additionalInlineLanguageLabelFiles'][] = $inlineLanguageLabelFile;
-            }
+        foreach ($childReturn['additionalInlineLanguageLabelFiles'] ?? [] as $inlineLanguageLabelFile) {
+            $existing['additionalInlineLanguageLabelFiles'][] = $inlineLanguageLabelFile;
         }
         if (!empty($childReturn['inlineData'])) {
             $existingInlineData = $existing['inlineData'];