Verified Commit b51c20d2 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #2916682 by Matroskeen: Defaults not working for grouped filter with multiple selections

(cherry picked from commit 25a2823e)
parent 646af0a7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -882,7 +882,7 @@ public function groupForm(&$form, FormStateInterface $form_state) {
        }
        unset($form[$value]['#default_value']);
        $user_input = $form_state->getUserInput();
        if (empty($user_input)) {
        if (empty($user_input[$value])) {
          $user_input[$value] = $this->group_info;
          $form_state->setUserInput($user_input);
        }
+31 −1
Original line number Diff line number Diff line
@@ -324,12 +324,27 @@ public function testExposedGroupedFilter() {
      'options[group_info][group_items][2][value][article]' => 'article',
      'options[group_info][group_items][3][title]' => '3rd',
      'options[group_info][group_items][3][value][page]' => 'page',
      'options[group_info][default_group]' => '3',
    ];
    // Apply the filter settings.
    $this->submitForm($edit, 'Apply');
    // Check that the view is saved without errors.
    $this->submitForm([], 'Save');
    $this->assertSession()->statusCodeEquals(200);
    // Check the default filter value.
    $this->drupalGet('test_exposed_admin_ui');
    $this->assertSession()->fieldValueEquals('type', '3');
    // Enable "Allow multiple selections" option and set a default group.
    $this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/type');
    $edit['options[group_info][multiple]'] = 1;
    $edit['options[group_info][default_group_multiple][1]'] = 1;
    $this->submitForm($edit, 'Apply');
    $this->submitForm([], 'Save');
    // Check the default filter values again.
    $this->drupalGet('test_exposed_admin_ui');
    $this->assertSession()->checkboxChecked('type[1]');
    $this->assertSession()->checkboxNotChecked('type[2]');
    $this->assertSession()->checkboxNotChecked('type[3]');

    // Click the Expose filter button.
    $this->drupalGet('admin/structure/views/nojs/add-handler/test_exposed_admin_ui/default/filter');
@@ -348,18 +363,33 @@ public function testExposedGroupedFilter() {
      'options[group_info][group_items][2][value]' => 1,
      'options[group_info][group_items][3][title]' => 'Unpublished',
      'options[group_info][group_items][3][value]' => 0,
      'options[group_info][default_group]' => 2,
    ];
    // Apply the filter settings.
    $this->submitForm($edit, 'Apply');
    // Check that the view is saved without errors.
    $this->submitForm([], 'Save');
    $this->assertSession()->statusCodeEquals(200);

    $this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/status');
    // Assert the same settings defined before still are there.
    $this->assertSession()->checkboxChecked('edit-options-group-info-group-items-1-value-all');
    $this->assertSession()->checkboxChecked('edit-options-group-info-group-items-2-value-1');
    $this->assertSession()->checkboxChecked('edit-options-group-info-group-items-3-value-0');

    // Check the default filter value.
    $this->drupalGet('test_exposed_admin_ui');
    $this->assertSession()->fieldValueEquals('status', '2');
    // Enable "Allow multiple selections" option and set a default group.
    $this->drupalGet('admin/structure/views/nojs/handler/test_exposed_admin_ui/default/filter/status');
    $edit['options[group_info][multiple]'] = 1;
    $edit['options[group_info][default_group_multiple][3]'] = 1;
    $this->submitForm($edit, 'Apply');
    $this->submitForm([], 'Save');
    // Check the default filter value again.
    $this->drupalGet('test_exposed_admin_ui');
    $this->assertSession()->checkboxNotChecked('status[1]');
    $this->assertSession()->checkboxNotChecked('status[2]');
    $this->assertSession()->checkboxChecked('status[3]');
  }

}