From 80af64f1fdd018d586b5c45e1b1ae6914eeeae3e Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Fri, 12 Jul 2024 11:47:15 +0200 Subject: [PATCH] Load tags if they are present in the `$data` array --- .../builder/field/tag/TagFormField.class.php | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/wcfsetup/install/files/lib/system/form/builder/field/tag/TagFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/tag/TagFormField.class.php index c930cafa1a..5e8df5b687 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/tag/TagFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/tag/TagFormField.class.php @@ -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; + } } } -- 2.20.1