From 491c8d2ae6c6a2f4a906b280deb7ee437cc7f0da Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 24 May 2018 17:27:35 +0200 Subject: [PATCH] Fix issues with `ShowOrderFormField` See #2509 --- .../field/ShowOrderFormField.class.php | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/wcfsetup/install/files/lib/system/form/builder/field/ShowOrderFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/ShowOrderFormField.class.php index 677ae9b851..c6ca5f2e28 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/ShowOrderFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/ShowOrderFormField.class.php @@ -1,5 +1,6 @@ getDocument()->getFormMode() === IFormDocument::FORM_MODE_UPDATE`, + * it is expected that the edited objects itself is not part of the sibling list provided + * for the field options. + * * @author Matthias Schmidt * @copyright 2001-2018 WoltLab GmbH * @license GNU Lesser General Public License @@ -32,7 +41,7 @@ class ShowOrderFormField extends SingleSelectionFormField { * @inheritDoc */ public function getSaveValue() { - if ($this->__value) { + if ($this->__value !== null) { $index = array_search($this->__value, array_keys($this->getOptions())); if ($index !== false) { @@ -56,10 +65,8 @@ class ShowOrderFormField extends SingleSelectionFormField { public function options($options): ISelectionFormField { parent::options($options); - $this->__options = array_merge( - [0 => WCF::getLanguage()->get('wcf.form.field.showOrder.firstPosition')], - $this->__options - ); + $this->__options = [0 => WCF::getLanguage()->get('wcf.form.field.showOrder.firstPosition')] + $this->__options; + $this->possibleValues[] = 0; return $this; } @@ -70,7 +77,13 @@ class ShowOrderFormField extends SingleSelectionFormField { public function value($value): IFormField { $keys = array_keys($this->getOptions()); - if (count($keys) < $value) { + // when editing an objects, the value has to be reduced by one to determine the + // relevant sibling as the edited object is shown after its previous sibling + if ($this->getDocument()->getFormMode() === IFormDocument::FORM_MODE_UPDATE) { + $value -= 1; + } + + if (count($keys) <= $value) { throw new \InvalidArgumentException("Unknown value '{$value}' as only " . count($keys) . " values are available."); } -- 2.20.1