From b8a0e9e9ecb37366e067098ddffd8532d9032c8a Mon Sep 17 00:00:00 2001 From: qadan Date: Fri, 2 Oct 2020 14:33:59 -0300 Subject: [PATCH] ensure weights for rows --- src/Plugin/views/field/IntegerWeightSelector.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Plugin/views/field/IntegerWeightSelector.php b/src/Plugin/views/field/IntegerWeightSelector.php index 141d3567..d42576f5 100644 --- a/src/Plugin/views/field/IntegerWeightSelector.php +++ b/src/Plugin/views/field/IntegerWeightSelector.php @@ -46,18 +46,16 @@ class IntegerWeightSelector extends FieldPluginBase { $options[$this->getValue($row)] = $this->getValue($row); } - // If we were given some blank values we need to fill - // out the option list from 1 through the result count - // to make sure we have enough. (Blanks should only appear - // at the beginning of the results list.) - // Also, blank values will break the selector, remove it. + // Blank values will break the selector, so remove one if found. if (array_key_exists('', $options)) { unset($options['']); - for ($i = 1; $i <= $this->view->total_rows; $i++) { - $options[$i] = $i; - } - ksort($options); } + // Add in values from the list of rows, starting at 0, to ensure we have + // numbers matching each possible row. + for ($i = 0; $i < $this->view->total_rows; $i++) { + $options[$i] = $i; + } + ksort($options); // Now that we have all the available weight values, populate the forms. foreach ($this->view->result as $row_index => $row) {