From e71b751e96a0c091e19f25e048dacb0e2a504262 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 12 May 2019 11:44:14 +0200 Subject: [PATCH] Fix double `(first position)` when using callable for show order field options See #2509 --- .../field/ShowOrderFormField.class.php | 22 ++++++++++++++----- 1 file changed, 16 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 77fe58392b..1bf964eeb9 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 @@ -31,6 +31,12 @@ use wcf\system\WCF; class ShowOrderFormField extends SingleSelectionFormField { use TDefaultIdFormField; + /** + * is `true` if `(first position)` option was added + * @var bool + */ + protected $addedFirstPositionOption = false; + /** * Creates a new instance of `ShowOrderFormField`. */ @@ -66,12 +72,16 @@ class ShowOrderFormField extends SingleSelectionFormField { public function options($options, $nestedOptions = false, $labelLanguageItems = true) { parent::options($options, $nestedOptions, $labelLanguageItems); - $this->options = [0 => WCF::getLanguage()->get('wcf.form.field.showOrder.firstPosition')] + $this->options; - array_unshift($this->nestedOptions, [ - 'depth' => 0, - 'label' => WCF::getLanguage()->get('wcf.form.field.showOrder.firstPosition'), - 'value' => 0 - ]); + if (!$this->addedFirstPositionOption) { + $this->options = [0 => WCF::getLanguage()->get('wcf.form.field.showOrder.firstPosition')] + $this->options; + array_unshift($this->nestedOptions, [ + 'depth' => 0, + 'label' => WCF::getLanguage()->get('wcf.form.field.showOrder.firstPosition'), + 'value' => 0 + ]); + + $this->addedFirstPositionOption = true; + } return $this; } -- 2.20.1