use wcf\util\StringUtil;
/**
- * Provides helper methods to interact with the label group.
+ * Manages the state of a label picker and renders the component.
*
* @author Alexander Ebert
* @copyright 2001-2023 WoltLab GmbH
if (!isset($this->elementID)) {
$this->elementID = \sprintf(
'%s_labelGroup%d',
- \substr(\md5($this->name), 0, 8),
+ \bin2hex(\random_bytes(16)),
$this->labelGroup->groupID,
);
}
/**
* Returns an unencoded query string for `labelIDs` for use in the LinkHandler.
- *
- * @return string
*/
public function toUrlQueryString(): string
{
return \implode(
'&',
- \array_filter(
- \array_map(static function (LabelPicker $labelPicker) {
- if (!$labelPicker->hasSelection()) {
- return '';
- }
-
- return \sprintf(
- 'labelIDs[%d]=%d',
- $labelPicker->labelGroup->groupID,
- $labelPicker->getSelectedValue(),
- );
- }, $this->labelPickers)
- )
+ \array_map(static function (LabelPicker $labelPicker) {
+ return \sprintf(
+ 'labelIDs[%d]=%d',
+ $labelPicker->labelGroup->groupID,
+ $labelPicker->getSelectedValue(),
+ );
+ }, \array_filter(
+ $this->labelPickers,
+ static fn (LabelPicker $labelPicker) => $labelPicker->hasSelection()
+ ))
);
}
*/
public function toLabelIDs(): array
{
- return \array_filter(
- \array_map(
- fn (LabelPicker $labelPicker) => $labelPicker->getSelectedValue(),
- $this->labelPickers
- ),
+ return \array_map(
+ static fn (LabelPicker $labelPicker) => $labelPicker->getSelectedValue(),
+ \array_filter(
+ $this->labelPickers,
+ static fn (LabelPicker $labelPicker) => $labelPicker->hasSelection()
+ )
);
}
public static function fromViewableLabelGroups(array $viewableLabelGroups, bool $invertible): self
{
$labelPickers = \array_map(
- fn (ViewableLabelGroup $viewableLabelGroup) => new LabelPicker($viewableLabelGroup, $invertible),
+ static fn (ViewableLabelGroup $viewableLabelGroup) => new LabelPicker($viewableLabelGroup, $invertible),
$viewableLabelGroups
);