Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure weights in integer weight select #800

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/Plugin/views/field/IntegerWeightSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,16 @@ public function viewsForm(array &$form, FormStateInterface $form_state) {
$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) {
Expand Down