-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathLabelAddForm.class.php
More file actions
124 lines (110 loc) · 4.03 KB
/
LabelAddForm.class.php
File metadata and controls
124 lines (110 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace wcf\acp\form;
use wcf\data\label\group\LabelGroupList;
use wcf\data\label\Label;
use wcf\data\label\LabelAction;
use wcf\data\label\LabelList;
use wcf\form\AbstractFormBuilderForm;
use wcf\system\exception\NamedUserException;
use wcf\system\form\builder\container\FormContainer;
use wcf\system\form\builder\field\BadgeColorFormField;
use wcf\system\form\builder\field\IFormField;
use wcf\system\form\builder\field\IntegerFormField;
use wcf\system\form\builder\field\SelectFormField;
use wcf\system\form\builder\field\ShowOrderFormField;
use wcf\system\form\builder\field\TextFormField;
use wcf\system\WCF;
use wcf\util\HtmlString;
/**
* Shows the label add form.
*
* @author Olaf Braun, Alexander Ebert
* @copyright 2001-2024 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*
* @extends AbstractFormBuilderForm<Label>
*/
class LabelAddForm extends AbstractFormBuilderForm
{
/**
* @inheritDoc
*/
public $activeMenuItem = 'wcf.acp.menu.link.label.add';
/**
* @inheritDoc
*/
public $neededPermissions = ['admin.content.label.canManageLabel'];
/**
* @inheritDoc
*/
public $objectEditLinkController = LabelEditForm::class;
/**
* @inheritDoc
*/
public $objectActionClass = LabelAction::class;
#[\Override]
protected function createForm()
{
parent::createForm();
$labelGroups = $this->getAvailableLabelGroups();
if ($labelGroups === []) {
throw new NamedUserException(
HtmlString::fromSafeHtml(WCF::getLanguage()->getDynamicVariable('wcf.acp.label.error.noGroups'))
);
}
$this->form->appendChildren([
FormContainer::create('section')
->appendChildren([
SelectFormField::create('groupID')
->label('wcf.acp.label.group')
->options($labelGroups, labelLanguageItems: false)
->immutable($this->formAction !== 'create')
->description('wcf.acp.label.group.permanentSelection')
->required(),
TextFormField::create('label')
->i18n()
->required()
->languageItemPattern('wcf.acp.label.label\d+'),
$this->getShowOrderField(),
BadgeColorFormField::create('cssClassName')
->label('wcf.acp.label.cssClassName')
->required()
->textReferenceNodeId('label')
])
]);
}
/**
* @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') {
return IntegerFormField::create('showOrder')
->addFieldClass('tiny')
->value(0)
->label('wcf.form.field.showOrder');
} else {
return ShowOrderFormField::create()
->options(function () {
$labelList = new LabelList();
$labelList->getConditionBuilder()->add('groupID = ?', [$this->formObject->groupID]);
$labelList->getConditionBuilder()->add('labelID <> ?', [$this->formObject->labelID]);
$labelList->sqlOrderBy = 'showOrder';
$labelList->readObjects();
return $labelList->getObjects();
});
}
}
}