From: Alexander Ebert Date: Sat, 11 Sep 2021 15:07:28 +0000 (+0200) Subject: Merge branch '5.3' into 5.4 X-Git-Tag: 5.4.8_dev_1~27 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c28c4c0ef501597badf8c8ac4ed291d9da39692c;p=GitHub%2FWoltLab%2FWCF.git Merge branch '5.3' into 5.4 --- c28c4c0ef501597badf8c8ac4ed291d9da39692c diff --cc wcfsetup/install/files/lib/system/form/builder/field/tag/TagFormField.class.php index ee4547f27d,145a0553d9..57680a5e4e --- 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 @@@ -21,179 -17,160 +21,179 @@@ use wcf\util\ArrayUtil * This field uses the `wcf.tagging.tags` and `wcf.tagging.tags.description` language * item as the default form field label and description, respectively. The default id * of fields of this class is `tags`. - * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @package WoltLabSuite\Core\System\Form\Builder\Field\Tag - * @since 5.2 + * + * @author Matthias Schmidt + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\System\Form\Builder\Field\Tag + * @since 5.2 */ -class TagFormField extends AbstractFormField implements IObjectTypeFormNode { - use TDefaultIdFormField; - use TObjectTypeFormNode; - - /** - * @inheritDoc - */ - protected $javaScriptDataHandlerModule = 'WoltLabSuite/Core/Form/Builder/Field/Tag'; - - /** - * @inheritDoc - */ - protected $templateName = '__tagFormField'; - - /** - * Creates a new instance of `TagFormField`. - */ - public function __construct() { - $this->description('wcf.tagging.tags.description'); - $this->label('wcf.tagging.tags'); - } - - /** - * @inheritDoc - */ - public function getObjectTypeDefinition() { - return 'com.woltlab.wcf.tagging.taggableObject'; - } - - /** - * @inheritDoc - */ - public function hasSaveValue() { - return false; - } - - /** - * @inheritDoc - */ - public function updatedObject(array $data, IStorableObject $object, $loadValues = true) { - if ($loadValues) { - $objectID = $object->{$object::getDatabaseTableIndexName()}; - - if ($objectID === null) { - throw new \UnexpectedValueException("Cannot read object id from object of class '" . get_class($object). "'."); - } - - if ($this->getObjectType() === null) { - throw new \UnexpectedValueException("Missing taggable object type."); - } - - $languageIDs = []; - - /** @noinspection PhpUndefinedFieldInspection */ - if (isset($data['languageID'])) { - $languageIDs[] = $data['languageID']; - } - - $tags = TagEngine::getInstance()->getObjectTags($this->getObjectType()->objectType, $objectID, $languageIDs); - - $this->value = []; - foreach ($tags as $tag) { - $this->value[] = $tag->name; - } - } - - return $this; - } - - /** - * @inheritDoc - */ - public function populate() { - parent::populate(); - - $this->getDocument()->getDataHandler()->addProcessor(new CustomFormDataProcessor('tags', function(IFormDocument $document, array $parameters) { - if ($this->checkDependencies() && $this->getValue() !== null && !empty($this->getValue())) { - $parameters[$this->getObjectProperty()] = $this->getValue(); - } - - return $parameters; - })); - - return $this; - } - - /** - * @inheritDoc - */ - public function readValue() { - if ($this->getDocument()->hasRequestData($this->getPrefixedId())) { - $value = $this->getDocument()->getRequestData($this->getPrefixedId()); - - if (is_array($value)) { - $this->value = ArrayUtil::trim($value); - } - } - - return $this; - } - - /** - * @inheritDoc - */ - public function value($value) { - if (!is_array($value)) { - throw new \InvalidArgumentException("Given value is no array, " . gettype($value) . " given."); - } - - $stringTags = []; - $stringValues = null; - - foreach ($value as $tag) { - if (is_string($tag)) { - if ($stringValues === null) { - $stringValues = true; - } - - if ($stringValues === false) { - throw new \InvalidArgumentException("Given value array contains mixed values, all values have to be either strings or `" . Tag::class . "` objects."); - } - - $stringTags[] = $tag; - } - else if ($tag instanceof Tag) { - if ($stringValues === null) { - $stringValues = false; - } - - if ($stringValues === true) { - throw new \InvalidArgumentException("Given value array contains mixed values, all values have to be either strings or `" . Tag::class . "` objects."); - } - - $stringTags[] = $tag->name; - } - else { - throw new \InvalidArgumentException("Given value array contains invalid value of type " . gettype($tag) . "."); - } - } - - return parent::value($stringTags); - } - - /** - * @inheritDoc - */ - protected static function getDefaultId() { - return 'tags'; - } +class TagFormField extends AbstractFormField implements IAttributeFormField, IObjectTypeFormNode +{ + use TInputAttributeFormField; + use TDefaultIdFormField; + use TObjectTypeFormNode; + + /** + * @inheritDoc + */ + protected $javaScriptDataHandlerModule = 'WoltLabSuite/Core/Form/Builder/Field/Tag'; + + /** + * @inheritDoc + */ + protected $templateName = '__tagFormField'; + + /** + * Creates a new instance of `TagFormField`. + */ + public function __construct() + { + $this->description('wcf.tagging.tags.description'); + $this->label('wcf.tagging.tags'); + } + + /** + * @inheritDoc + */ + public function getObjectTypeDefinition() + { + return 'com.woltlab.wcf.tagging.taggableObject'; + } + + /** + * @inheritDoc + */ + public function hasSaveValue() + { + return false; + } + + /** + * @inheritDoc + */ + public function updatedObject(array $data, IStorableObject $object, $loadValues = true) + { + if ($loadValues) { + $objectID = $object->{$object::getDatabaseTableIndexName()}; + + if ($objectID === null) { + throw new \UnexpectedValueException( + "Cannot read object id from object of class '" . \get_class($object) . "'." + ); + } + + if ($this->getObjectType() === null) { + throw new \UnexpectedValueException("Missing taggable object type."); + } + + $languageIDs = []; + + /** @noinspection PhpUndefinedFieldInspection */ + if (isset($data['languageID'])) { + $languageIDs[] = $data['languageID']; + } + + $tags = TagEngine::getInstance()->getObjectTags( + $this->getObjectType()->objectType, + $objectID, + $languageIDs + ); + + $this->value = []; + foreach ($tags as $tag) { + $this->value[] = $tag->name; + } + } + + return $this; + } + + /** + * @inheritDoc + */ + public function populate() + { + parent::populate(); + + $this->getDocument()->getDataHandler()->addProcessor(new CustomFormDataProcessor( - 'acl', ++ 'tags', + function (IFormDocument $document, array $parameters) { + if ($this->checkDependencies() && $this->getValue() !== null && !empty($this->getValue())) { + $parameters[$this->getObjectProperty()] = $this->getValue(); + } + + return $parameters; + } + )); + + return $this; + } + + /** + * @inheritDoc + */ + public function readValue() + { + if ($this->getDocument()->hasRequestData($this->getPrefixedId())) { + $value = $this->getDocument()->getRequestData($this->getPrefixedId()); + + if (\is_array($value)) { + $this->value = ArrayUtil::trim($value); + } + } + + return $this; + } + + /** + * @inheritDoc + */ + public function value($value) + { + if (!\is_array($value)) { + throw new \InvalidArgumentException("Given value is no array, " . \gettype($value) . " given."); + } + + $stringTags = []; + $stringValues = null; + + foreach ($value as $tag) { + if (\is_string($tag)) { + if ($stringValues === null) { + $stringValues = true; + } + + if ($stringValues === false) { + throw new \InvalidArgumentException("Given value array contains mixed values, all values have to be either strings or `" . Tag::class . "` objects."); + } + + $stringTags[] = $tag; + } elseif ($tag instanceof Tag) { + if ($stringValues === null) { + $stringValues = false; + } + + if ($stringValues === true) { + throw new \InvalidArgumentException("Given value array contains mixed values, all values have to be either strings or `" . Tag::class . "` objects."); + } + + $stringTags[] = $tag->name; + } else { + throw new \InvalidArgumentException( + "Given value array contains invalid value of type " . \gettype($tag) . "." + ); + } + } + + return parent::value($stringTags); + } + + /** + * @inheritDoc + */ + protected static function getDefaultId() + { + return 'tags'; + } }