From 3689b707ecd132368019b5f4075a51502ba88158 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 13 Oct 2023 15:39:49 +0200 Subject: [PATCH] Use `\http_build_query()` and the proper name to build the query string --- .../system/label/LabelPickerGroup.class.php | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php b/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php index 2df533ef87..8851232d10 100644 --- a/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php +++ b/wcfsetup/install/files/lib/system/label/LabelPickerGroup.class.php @@ -23,9 +23,9 @@ final class LabelPickerGroup implements \Countable, \IteratorAggregate private readonly array $labelPickers; /** - * @var list + * Field name of the selected values. */ - private readonly array $positionToGroupID; + private string $name = 'labelIDs'; /** * @param LabelPicker[] $labelPickers @@ -43,7 +43,6 @@ final class LabelPickerGroup implements \Countable, \IteratorAggregate } $this->labelPickers = $pickers; - $this->positionToGroupID = \array_keys($pickers); } /** @@ -98,19 +97,15 @@ final class LabelPickerGroup implements \Countable, \IteratorAggregate */ public function toUrlQueryString(): string { - return \implode( - '&', - \array_map(static function (LabelPicker $labelPicker) { - return \sprintf( - 'labelIDs[%d]=%d', - $labelPicker->labelGroup->groupID, - $labelPicker->getSelectedValue(), - ); - }, \array_filter( + $mapping = \array_map( + static fn (LabelPicker $labelPicker) => $labelPicker->getSelectedValue(), + \array_filter( $this->labelPickers, static fn (LabelPicker $labelPicker) => $labelPicker->hasSelection() - )) + ) ); + + return \http_build_query([$this->name => $mapping], '', '&'); } /** @@ -192,6 +187,8 @@ final class LabelPickerGroup implements \Countable, \IteratorAggregate */ public function setName(string $name): void { + $this->name = $name; + foreach ($this->labelPickers as $labelPicker) { $labelPicker->name = $name; } -- 2.20.1