Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions wcfsetup/install/files/lib/acp/form/LabelAddForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
);
Expand All @@ -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(),
Expand All @@ -84,6 +83,24 @@ protected function createForm()
]);
}

/**
* @return array<int, string>
*/
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') {
Expand Down
18 changes: 18 additions & 0 deletions wcfsetup/install/files/lib/data/label/group/LabelGroup.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -135,4 +127,22 @@ protected function getInitializedEvent(): LabelGridViewInitialized
{
return new LabelGridViewInitialized($this);
}

/**
* @return array<int, string>
*/
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;
}
}