Fix double `(first position)` when using callable for show order field options
authorMatthias Schmidt <gravatronics@live.com>
Sun, 12 May 2019 09:44:14 +0000 (11:44 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 12 May 2019 09:44:14 +0000 (11:44 +0200)
See #2509

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

index 77fe58392b69de0721fc1dc6eafab2926dda2971..1bf964eeb9a260bd3f837e84811c10879d06f2f3 100644 (file)
@@ -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;
        }