Skip to content

Commit d1a2289

Browse files
committed
Fix the editing the show order of nested categories
See https://www.woltlab.com/community/thread/317059/
1 parent 495b07a commit d1a2289

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

wcfsetup/install/files/lib/acp/form/CategoryAddFormBuilderForm.class.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use wcf\system\form\builder\data\processor\CustomFormDataProcessor;
2424
use wcf\system\form\builder\field\acl\AclFormField;
2525
use wcf\system\form\builder\field\BooleanFormField;
26+
use wcf\system\form\builder\field\IntegerFormField;
2627
use wcf\system\form\builder\field\MultilineTextFormField;
2728
use wcf\system\form\builder\field\SelectFormField;
2829
use wcf\system\form\builder\field\ShowOrderFormField;
@@ -243,6 +244,23 @@ protected function getPositionFormFields(): array
243244
$categoryNodeTree->setMaxDepth($maximumNestingLevel - 1);
244245
}
245246

247+
$positionFormField = null;
248+
if ($maximumNestingLevel === 0) {
249+
$positionFormField = ShowOrderFormField::create()
250+
->description($processor->getLanguageVariable('showOrder.description', true))
251+
->options($categoryNodeTree, true)
252+
->nullable()
253+
->required();
254+
} else {
255+
// Provide a simple integer input instead because we cannot
256+
// dynamically filter the list of categories in the position field.
257+
$positionFormField = IntegerFormField::create('showOrder')
258+
->label('wcf.form.field.showOrder')
259+
->description($processor->getLanguageVariable('showOrder.description', true))
260+
->minimum(0)
261+
->required();
262+
}
263+
246264
return [
247265
SelectFormField::create('parentCategoryID')
248266
->label($processor->getLanguageVariable('parentCategoryID'))
@@ -336,11 +354,7 @@ static function (SelectFormField $formField) use ($processor) {
336354
}
337355
)
338356
),
339-
ShowOrderFormField::create()
340-
->description($processor->getLanguageVariable('showOrder.description', true))
341-
->options($categoryNodeTree, true)
342-
->nullable()
343-
->required(),
357+
$positionFormField,
344358
];
345359
}
346360

wcfsetup/install/files/lib/system/form/builder/field/RadioButtonFormField.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function supportsNestedOptions()
6363
public function validate()
6464
{
6565
if ($this->isRequired() || $this->getValue() !== '') {
66-
if (!isset($this->getOptions()[$this->getValue()])) {
66+
if ($this->getValue() === null || !isset($this->getOptions()[$this->getValue()])) {
6767
$this->addValidationError(
6868
new FormFieldValidationError(
6969
'invalidValue',

0 commit comments

Comments
 (0)