Load tags if they are present in the `$data` array
authorCyperghost <olaf_schmitz_1@t-online.de>
Fri, 12 Jul 2024 09:47:15 +0000 (11:47 +0200)
committerCyperghost <olaf_schmitz_1@t-online.de>
Fri, 12 Jul 2024 09:47:15 +0000 (11:47 +0200)
wcfsetup/install/files/lib/system/form/builder/field/tag/TagFormField.class.php

index c930cafa1a23734b8f74fedc8d4a343e0628b37d..5e8df5b687919f8ea16b261db25bf96404c823e6 100644 (file)
@@ -75,34 +75,38 @@ final class TagFormField extends AbstractFormField implements IAttributeFormFiel
     public function updatedObject(array $data, IStorableObject $object, $loadValues = true)
     {
         if ($loadValues) {
-            $objectID = $object->{$object::getDatabaseTableIndexName()};
+            if (isset($data[$this->getObjectProperty()])) {
+                $this->value($data[$this->getObjectProperty()]);
+            } else {
+                $objectID = $object->{$object::getDatabaseTableIndexName()};
 
-            if ($objectID === null) {
-                throw new \UnexpectedValueException(
-                    "Cannot read object id from object of class '" . \get_class($object) . "' for field '{$this->getId()}'."
-                );
-            }
+                if ($objectID === null) {
+                    throw new \UnexpectedValueException(
+                        "Cannot read object id from object of class '" . \get_class($object) . "' for field '{$this->getId()}'."
+                    );
+                }
 
-            if ($this->getObjectType() === null) {
-                throw new \UnexpectedValueException("Missing taggable object type for field '{$this->getId()}'.");
-            }
+                if ($this->getObjectType() === null) {
+                    throw new \UnexpectedValueException("Missing taggable object type for field '{$this->getId()}'.");
+                }
 
-            $languageIDs = [];
+                $languageIDs = [];
 
-            /** @noinspection PhpUndefinedFieldInspection */
-            if (isset($data['languageID'])) {
-                $languageIDs[] = $data['languageID'];
-            }
+                /** @noinspection PhpUndefinedFieldInspection */
+                if (isset($data['languageID'])) {
+                    $languageIDs[] = $data['languageID'];
+                }
 
-            $tags = TagEngine::getInstance()->getObjectTags(
-                $this->getObjectType()->objectType,
-                $objectID,
-                $languageIDs
-            );
+                $tags = TagEngine::getInstance()->getObjectTags(
+                    $this->getObjectType()->objectType,
+                    $objectID,
+                    $languageIDs
+                );
 
-            $this->value = [];
-            foreach ($tags as $tag) {
-                $this->value[] = $tag->name;
+                $this->value = [];
+                foreach ($tags as $tag) {
+                    $this->value[] = $tag->name;
+                }
             }
         }