Loading core/modules/views/src/ViewExecutable.php +10 −9 Original line number Diff line number Diff line Loading @@ -712,15 +712,16 @@ public function getExposedInput() { } // If we have no input at all, check for remembered input via session. if (empty($this->exposed_input) && $this->request->hasSession()) { $session = \Drupal::request()->getSession(); // If filters are not overridden, store the 'remember' settings on the // default display. If they are, store them on this display. This way, // multiple displays in the same view can share the same filters and // remember settings. $display_id = ($this->display_handler->isDefaulted('filters')) ? 'default' : $this->current_display; if (empty($this->exposed_input) && !empty($_SESSION['views'][$this->storage->id()][$display_id])) { $this->exposed_input = $_SESSION['views'][$this->storage->id()][$display_id]; if (!empty($session->get('views')[$this->storage->id()][$display_id])) { $this->exposed_input = $session->get('views')[$this->storage->id()][$display_id]; } } } Loading core/modules/views/tests/modules/views_test_config/test_views/views.view.test_remember_selected.yml 0 → 100644 +110 −0 Original line number Diff line number Diff line langcode: en status: true dependencies: config: - core.entity_view_mode.node.teaser module: - node id: test_remember_selected label: '' module: views description: '' tag: '' base_table: node_field_data base_field: nid display: default: id: default display_title: Default display_plugin: default position: 0 display_options: pager: type: full exposed_form: type: basic options: reset_button: true access: type: none cache: type: none options: { } filters: type: id: type table: node_field_data field: type relationship: none group_type: group admin_label: '' entity_type: node entity_field: type plugin_id: in_operator operator: in value: { } group: 1 exposed: true expose: operator_id: type_op label: 'Content: Type' description: 'Exposed description' use_operator: false operator: '' operator_limit_selection: false operator_list: { } identifier: type required: false remember: true multiple: false remember_roles: anonymous: anonymous authenticated: authenticated content_editor: '0' administrator: '0' reduce: false is_grouped: false group_info: label: '' description: '' identifier: '' optional: true widget: select multiple: false remember: false default_group: All default_group_multiple: { } group_items: { } style: type: default row: type: 'entity:node' query: type: views_query options: query_comment: '' display_extenders: { } cache_metadata: max-age: -1 contexts: - 'languages:language_interface' - url - url.query_args - 'user.node_grants:view' tags: { } page_1: id: page_1 display_title: Page display_plugin: page position: 0 display_options: display_extenders: { } path: test_remember_selected cache_metadata: max-age: -1 contexts: - 'languages:language_interface' - url - url.query_args - 'user.node_grants:view' tags: { } core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php +14 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ class ExposedFormTest extends ViewTestBase { * * @var array */ public static $testViews = ['test_exposed_form_buttons', 'test_exposed_block', 'test_exposed_form_sort_items_per_page', 'test_exposed_form_pager']; public static $testViews = ['test_exposed_form_buttons', 'test_exposed_block', 'test_exposed_form_sort_items_per_page', 'test_exposed_form_pager', 'test_remember_selected']; /** * Modules to enable. Loading Loading @@ -510,4 +510,17 @@ protected function assertNodesExist(array $bundles): void { } } /** * Tests the "Remember the last selection" functionality. */ public function testRememberSelected() { $this->drupalGet('test_remember_selected'); $this->getSession()->getPage()->fillField('type', 'page'); $this->getSession()->getPage()->pressButton('Apply'); // Reload the page and ensure the filter is selected. $this->drupalGet('test_remember_selected'); $this->assertTrue($this->assertSession()->optionExists('type', 'page')->isSelected()); } } Loading
core/modules/views/src/ViewExecutable.php +10 −9 Original line number Diff line number Diff line Loading @@ -712,15 +712,16 @@ public function getExposedInput() { } // If we have no input at all, check for remembered input via session. if (empty($this->exposed_input) && $this->request->hasSession()) { $session = \Drupal::request()->getSession(); // If filters are not overridden, store the 'remember' settings on the // default display. If they are, store them on this display. This way, // multiple displays in the same view can share the same filters and // remember settings. $display_id = ($this->display_handler->isDefaulted('filters')) ? 'default' : $this->current_display; if (empty($this->exposed_input) && !empty($_SESSION['views'][$this->storage->id()][$display_id])) { $this->exposed_input = $_SESSION['views'][$this->storage->id()][$display_id]; if (!empty($session->get('views')[$this->storage->id()][$display_id])) { $this->exposed_input = $session->get('views')[$this->storage->id()][$display_id]; } } } Loading
core/modules/views/tests/modules/views_test_config/test_views/views.view.test_remember_selected.yml 0 → 100644 +110 −0 Original line number Diff line number Diff line langcode: en status: true dependencies: config: - core.entity_view_mode.node.teaser module: - node id: test_remember_selected label: '' module: views description: '' tag: '' base_table: node_field_data base_field: nid display: default: id: default display_title: Default display_plugin: default position: 0 display_options: pager: type: full exposed_form: type: basic options: reset_button: true access: type: none cache: type: none options: { } filters: type: id: type table: node_field_data field: type relationship: none group_type: group admin_label: '' entity_type: node entity_field: type plugin_id: in_operator operator: in value: { } group: 1 exposed: true expose: operator_id: type_op label: 'Content: Type' description: 'Exposed description' use_operator: false operator: '' operator_limit_selection: false operator_list: { } identifier: type required: false remember: true multiple: false remember_roles: anonymous: anonymous authenticated: authenticated content_editor: '0' administrator: '0' reduce: false is_grouped: false group_info: label: '' description: '' identifier: '' optional: true widget: select multiple: false remember: false default_group: All default_group_multiple: { } group_items: { } style: type: default row: type: 'entity:node' query: type: views_query options: query_comment: '' display_extenders: { } cache_metadata: max-age: -1 contexts: - 'languages:language_interface' - url - url.query_args - 'user.node_grants:view' tags: { } page_1: id: page_1 display_title: Page display_plugin: page position: 0 display_options: display_extenders: { } path: test_remember_selected cache_metadata: max-age: -1 contexts: - 'languages:language_interface' - url - url.query_args - 'user.node_grants:view' tags: { }
core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php +14 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,7 @@ class ExposedFormTest extends ViewTestBase { * * @var array */ public static $testViews = ['test_exposed_form_buttons', 'test_exposed_block', 'test_exposed_form_sort_items_per_page', 'test_exposed_form_pager']; public static $testViews = ['test_exposed_form_buttons', 'test_exposed_block', 'test_exposed_form_sort_items_per_page', 'test_exposed_form_pager', 'test_remember_selected']; /** * Modules to enable. Loading Loading @@ -510,4 +510,17 @@ protected function assertNodesExist(array $bundles): void { } } /** * Tests the "Remember the last selection" functionality. */ public function testRememberSelected() { $this->drupalGet('test_remember_selected'); $this->getSession()->getPage()->fillField('type', 'page'); $this->getSession()->getPage()->pressButton('Apply'); // Reload the page and ensure the filter is selected. $this->drupalGet('test_remember_selected'); $this->assertTrue($this->assertSession()->optionExists('type', 'page')->isSelected()); } }