diff --git a/wcfsetup/install/files/lib/acp/form/LabelAddForm.class.php b/wcfsetup/install/files/lib/acp/form/LabelAddForm.class.php index 39e36ee6296..431d1dbebcb 100644 --- a/wcfsetup/install/files/lib/acp/form/LabelAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/LabelAddForm.class.php @@ -54,9 +54,8 @@ protected function createForm() { parent::createForm(); - $labelGroupList = new LabelGroupList(); - $labelGroupList->readObjects(); - if ($labelGroupList->count() === 0) { + $labelGroups = $this->getAvailableLabelGroups(); + if ($labelGroups === []) { throw new NamedUserException( HtmlString::fromSafeHtml(WCF::getLanguage()->getDynamicVariable('wcf.acp.label.error.noGroups')) ); @@ -67,7 +66,7 @@ protected function createForm() ->appendChildren([ SelectFormField::create('groupID') ->label('wcf.acp.label.group') - ->options($labelGroupList) + ->options($labelGroups, labelLanguageItems: false) ->immutable($this->formAction !== 'create') ->description('wcf.acp.label.group.permanentSelection') ->required(), @@ -84,6 +83,24 @@ protected function createForm() ]); } + /** + * @return array + */ + protected function getAvailableLabelGroups(): array + { + $labelGroupList = new LabelGroupList(); + $labelGroupList->readObjects(); + $labelGroups = \array_map(static fn($group) => $group->getExtendedTitle(), $labelGroupList->getObjects()); + + $collator = new \Collator(WCF::getLanguage()->getLocale()); + \uasort( + $labelGroups, + static fn(string $groupA, string $groupB) => $collator->compare($groupA, $groupB) + ); + + return $labelGroups; + } + protected function getShowOrderField(): IFormField { if ($this->formAction === 'create') { diff --git a/wcfsetup/install/files/lib/data/label/group/LabelGroup.class.php b/wcfsetup/install/files/lib/data/label/group/LabelGroup.class.php index 50f5392b058..ffcaf6b85d7 100644 --- a/wcfsetup/install/files/lib/data/label/group/LabelGroup.class.php +++ b/wcfsetup/install/files/lib/data/label/group/LabelGroup.class.php @@ -37,6 +37,24 @@ public function __toString(): string return $this->getTitle(); } + /** + * Returns the title and, if available, the description as a combined string. + * + * @since 6.2 + */ + public function getExtendedTitle(): string + { + if (!$this->groupDescription) { + return $this->getTitle(); + } + + return \sprintf( + "%s / %s", + $this->getTitle(), + $this->groupDescription + ); + } + /** * Callback for uasort() to sort label groups by show order and (if equal) group id. * diff --git a/wcfsetup/install/files/lib/system/gridView/admin/LabelGridView.class.php b/wcfsetup/install/files/lib/system/gridView/admin/LabelGridView.class.php index 69053e4d0eb..43df7e7cd47 100644 --- a/wcfsetup/install/files/lib/system/gridView/admin/LabelGridView.class.php +++ b/wcfsetup/install/files/lib/system/gridView/admin/LabelGridView.class.php @@ -4,6 +4,7 @@ use wcf\acp\form\LabelEditForm; use wcf\data\DatabaseObject; +use wcf\data\label\group\LabelGroupList; use wcf\data\label\group\ViewableLabelGroup; use wcf\data\label\I18nLabelList; use wcf\data\label\Label; @@ -77,25 +78,16 @@ public function render(mixed $value, DatabaseObject $row): string $group = $groups[$row->groupID]; \assert($group instanceof ViewableLabelGroup); - if (empty($group->groupDescription)) { - return StringUtil::encodeHTML($group->getTitle()); - } - return \sprintf( - "%s / %s", - StringUtil::encodeHTML($group->getTitle()), - StringUtil::encodeHTML($group->groupDescription) - ); + return StringUtil::encodeHTML($group->getExtendedTitle()); } } ) ->filter( new SelectFilter( - \array_map( - static fn(ViewableLabelGroup $group) => $group->getTitle(), - LabelCacheBuilder::getInstance()->getData(arrayIndex: "groups"), - ), + $this->getAvailableLabelGroups(), 'groupID', - 'wcf.acp.label.group' + 'wcf.acp.label.group', + labelLanguageItems: false ) ) ->sortable(), @@ -135,4 +127,22 @@ protected function getInitializedEvent(): LabelGridViewInitialized { return new LabelGridViewInitialized($this); } + + /** + * @return array + */ + protected function getAvailableLabelGroups(): array + { + $labelGroupList = new LabelGroupList(); + $labelGroupList->readObjects(); + $labelGroups = \array_map(static fn($group) => $group->getExtendedTitle(), $labelGroupList->getObjects()); + + $collator = new \Collator(WCF::getLanguage()->getLocale()); + \uasort( + $labelGroups, + static fn(string $groupA, string $groupB) => $collator->compare($groupA, $groupB) + ); + + return $labelGroups; + } }