diff --git a/includes/view.inc b/includes/view.inc index d8c0c1f..7dd93db 100644 --- a/includes/view.inc +++ b/includes/view.inc @@ -411,18 +411,8 @@ class view extends views_db_object { * Figure out what the exposed input for this view is. */ function get_exposed_input() { - // Fill our input either from $_GET or from something previously set on the - // view. if (empty($this->exposed_input)) { - $this->exposed_input = $_GET; - // unset items that are definitely not our input: - foreach (array('page', 'q') as $key) { - if (isset($this->exposed_input[$key])) { - unset($this->exposed_input[$key]); - } - } - - // If we have no input at all, check for remembered input via session. + $this->exposed_input = array(); // If filters are not overridden, store the 'remember' settings on the // default display. If they are, store them on this display. This way, @@ -430,9 +420,17 @@ class view extends views_db_object { // remember settings. $display_id = ($this->display_handler->is_defaulted('filters')) ? 'default' : $this->current_display; - if (empty($this->exposed_input) && !empty($_SESSION['views'][$this->name][$display_id])) { + // Start with remembered input via session. + if (!empty($_SESSION['views'][$this->name][$display_id])) { $this->exposed_input = $_SESSION['views'][$this->name][$display_id]; } + + // Fetch exposed input values from $_GET. Overwrite if clashing. + foreach ($_GET as $key => $value) { + if (!in_array($key, array('page', 'q'))) { + $this->exposed_input[$key] = $value; + } + } } return $this->exposed_input; diff --git a/tests/views_exposed_form.test b/tests/views_exposed_form.test index 72baf2c..afa4f42 100644 --- a/tests/views_exposed_form.test +++ b/tests/views_exposed_form.test @@ -57,6 +57,38 @@ class ViewsExposedFormTest extends ViewsSqlTest { } /** + * Tests that exposed values are correctly stored. + */ + public function testRemember() { + $account = $this->drupalCreateUser(); + $this->drupalLogin($account); + // Create some random nodes. + for ($i = 0; $i < 5; $i++) { + $this->drupalCreateNode(); + } + + // Set the exposed filter. + $this->drupalGet('test_exposed_remember', array('query' => array('type' => 'page'))); + $this->assertFieldByName('type', 'page'); + + // Request the page again, should still be set. + $this->drupalGet('test_exposed_remember'); + $this->assertFieldByName('type', 'page'); + + // Request the page with an unrelated GET argument, filter should still be set. + $this->drupalGet('test_exposed_remember', array('query' => array('argument' => 'value'))); + $this->assertFieldByName('type', 'page'); + + // Change the remembered exposed value. + $this->drupalGet('test_exposed_remember', array('query' => array('type' => 'article'))); + $this->assertFieldByName('type', 'article'); + + // Request the page again, should have remembered the new value. + $this->drupalGet('test_exposed_remember'); + $this->assertFieldByName('type', 'article'); + } + + /** * Tests the admin interface of exposed filter and sort items. */ function testExposedAdminUi() { diff --git a/tests/views_test.views_default.inc b/tests/views_test.views_default.inc index 0448705..8843b26 100644 --- a/tests/views_test.views_default.inc +++ b/tests/views_test.views_default.inc @@ -218,5 +218,61 @@ function views_test_views_default_views() { $views[$view->name] = $view; + $view = new view(); + $view->name = 'test_exposed_remember'; + $view->description = ''; + $view->tag = ''; + $view->base_table = 'node'; + $view->human_name = 'test_exposed_remember'; + $view->core = 0; + $view->api_version = '3.0'; + $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ + + /* Display: Master */ + $handler = $view->new_display('default', 'Master', 'default'); + $handler->display->display_options['use_more_always'] = FALSE; + $handler->display->display_options['access']['type'] = 'none'; + $handler->display->display_options['cache']['type'] = 'none'; + $handler->display->display_options['query']['type'] = 'views_query'; + $handler->display->display_options['exposed_form']['type'] = 'basic'; + $handler->display->display_options['exposed_form']['options']['reset_button'] = TRUE; + $handler->display->display_options['pager']['type'] = 'none'; + $handler->display->display_options['style_plugin'] = 'default'; + $handler->display->display_options['row_plugin'] = 'node'; + /* Sort criterion: Content: Post date */ + $handler->display->display_options['sorts']['created']['id'] = 'created'; + $handler->display->display_options['sorts']['created']['table'] = 'node'; + $handler->display->display_options['sorts']['created']['field'] = 'created'; + /* Filter criterion: Content: Type */ + $handler->display->display_options['filters']['type']['id'] = 'type'; + $handler->display->display_options['filters']['type']['table'] = 'node'; + $handler->display->display_options['filters']['type']['field'] = 'type'; + $handler->display->display_options['filters']['type']['exposed'] = TRUE; + $handler->display->display_options['filters']['type']['expose']['operator_id'] = 'type_op'; + $handler->display->display_options['filters']['type']['expose']['label'] = 'Type'; + $handler->display->display_options['filters']['type']['expose']['operator'] = 'type_op'; + $handler->display->display_options['filters']['type']['expose']['identifier'] = 'type'; + $handler->display->display_options['filters']['type']['expose']['remember'] = TRUE; + $handler->display->display_options['filters']['type']['expose']['remember_roles'] = array( + 2 => '2', + ); + + /* Display: Page */ + $handler = $view->new_display('page', 'Page', 'page_1'); + $handler->display->display_options['path'] = 'test_exposed_remember'; + $translatables['test_exposed_remember'] = array( + t('Master'), + t('more'), + t('Apply'), + t('Reset'), + t('Sort by'), + t('Asc'), + t('Desc'), + t('Type'), + t('Page'), + ); + + $views[$view->name] = $view; + return $views; }