Fix LabelFormField for objects without labels
authorPeter Frühwirt <peter.fruehwirt@viecode.com>
Sat, 7 Dec 2019 16:26:35 +0000 (17:26 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 7 Dec 2019 16:26:35 +0000 (17:26 +0100)
LabelHandler will return an empty array if no label was attached to an object, which will result in undefined offset error in the LabelFormField

wcfsetup/install/files/lib/system/form/builder/field/label/LabelFormField.class.php

index ce3d6476a7dde0c6d598c999703c4db08abdbba6..8d8351193974b98b65382ae0d6e678f259a3ae03 100644 (file)
@@ -105,10 +105,11 @@ class LabelFormField extends AbstractFormField implements IObjectTypeFormNode {
                                static::$loadedLabels[$objectTypeID] = [];
                        }
                        if (!isset(static::$loadedLabels[$objectTypeID][$objectID])) {
-                               static::$loadedLabels[$objectTypeID][$objectID] = LabelHandler::getInstance()->getAssignedLabels(
+                               $assignedLabels = LabelHandler::getInstance()->getAssignedLabels(
                                        $objectTypeID,
                                        [$objectID]
-                               )[$objectID];
+                               );
+                               static::$loadedLabels[$objectTypeID][$objectID] = isset($assignedLabels[$objectID]) ? $assignedLabels[$objectID] : [];
                        }
                        
                        $labelIDs = $this->getLabelGroup()->getLabelIDs();