diff --git a/lib/Drupal/views/Tests/UI/RedirectTest.php b/lib/Drupal/views/Tests/UI/RedirectTest.php new file mode 100644 index 0000000000000000000000000000000000000000..a5a9d40ab371109bd3077cc0fdb63c8e3525c76e --- /dev/null +++ b/lib/Drupal/views/Tests/UI/RedirectTest.php @@ -0,0 +1,50 @@ +<?php + +/** + * @file + * Definition of Drupal\views\tests\UI\RedirectTest. + */ + +namespace Drupal\views\Tests\UI; + +/** + * Tests the redirecting after saving a views. + */ +class RedirectTest extends UITestBase { + + public static function getInfo() { + return array( + 'name' => 'Redirect', + 'description' => 'Tests the redirecting after saving a views', + 'group' => 'Views UI', + ); + } + + /** + * Tests the redirecting. + */ + public function testRedirect() { + $view = $this->getBasicView(); + + $random_destination = $this->randomName(); + $edit_path = "admin/structure/views/view/{$view->storage->name}/edit"; + + $this->drupalPost($edit_path, array(), t('Save') , array('query' => array('destination' => $random_destination))); + $this->assertUrl($random_destination, array(), 'Make sure the user got redirected to the expected page defined in the destination.'); + + // Setup a view with a certain page display path. If you change the path + // but have the old url in the destination the user should be redirected to + // the new path. + $view = views_get_view('test_redirect_view'); + $random_destination = $this->randomName(); + $new_path = $this->randomName(); + + $edit_path = "admin/structure/views/view/{$view->storage->name}/edit"; + $path_edit_path = "admin/structure/views/nojs/display/{$view->storage->name}/page_1/path"; + + $this->drupalPost($path_edit_path, array('path' => $new_path), t('Apply')); + $this->drupalPost($edit_path, array(), t('Save'), array('query' => array('destination' => 'test-redirect-view'))); + $this->assertUrl($new_path, array(), 'Make sure the user got redirected to the expected page after changing the url of a page display.'); + } + +} diff --git a/tests/views_test_config/config/views.view.test_redirect_view.yml b/tests/views_test_config/config/views.view.test_redirect_view.yml new file mode 100644 index 0000000000000000000000000000000000000000..121769301b46daae85f58d440b9fe764262541d2 --- /dev/null +++ b/tests/views_test_config/config/views.view.test_redirect_view.yml @@ -0,0 +1,79 @@ +base_table: node +name: test_redirect_view +description: '' +tag: '' +human_name: test_redirect_view +core: 8.x +api_version: '3.0' +display: + default: + display_plugin: default + id: default + display_title: Master + position: '' + display_options: + access: + type: perm + cache: + type: none + query: + type: views_query + exposed_form: + type: basic + pager: + type: full + options: + items_per_page: '10' + style: + type: default + row: + type: node + options: + build_mode: teaser + links: '1' + comments: '0' + fields: + title: + id: title + table: node + field: title + label: '' + alter: + alter_text: '0' + make_link: '0' + absolute: '0' + trim: '0' + word_boundary: '0' + ellipsis: '0' + strip_tags: '0' + html: '0' + hide_empty: '0' + empty_zero: '0' + link_to_node: '1' + filters: + status: + value: '1' + table: node + field: status + id: status + expose: + operator: '0' + group: '1' + sorts: + created: + id: created + table: node + field: created + order: DESC + title: test_redirect_view + page_1: + display_plugin: page + id: page_1 + display_title: Page + position: '' + display_options: + path: test-redirect-view +base_field: nid +disabled: '0' +module: views +langcode: und diff --git a/views_ui/admin.inc b/views_ui/admin.inc index 08126925cff6465861b2a30ecf1b4c958cafed0b..c7fbdc73794a1baed1ea5d549b644123ffa67a23 100644 --- a/views_ui/admin.inc +++ b/views_ui/admin.inc @@ -624,15 +624,20 @@ function views_ui_edit_view_form_submit($form, &$form_state) { if (!empty($destination)) { // Find out the first display which has a changed path and redirect to this url. $old_view = views_get_view($form_state['view']->storage->name); + $old_view->initDisplay(); foreach ($old_view->displayHandlers as $id => $display) { // Only check for displays with a path. - if (!isset($display->display['display_options']['path'])) { + $old_path = $display->getOption('path'); + if (empty($old_path)) { continue; } - $old_path = $display->display['display_options']['path']; - if (($display->display['display_plugin'] == 'page') && ($old_path == $destination) && ($old_path != $form_state['view']->display[$id]->display['display_options']['path'])) { - $destination = $form_state['view']->displayHandlers[$id]->display['display_options']['path']; + + if (($display->getPluginId() == 'page') && ($old_path == $destination) && ($old_path != $form_state['view']->displayHandlers[$id]->getOption('path'))) { + $destination = $form_state['view']->displayHandlers[$id]->getOption('path'); $query->remove('destination'); + // @todo For whatever reason drupal_goto is still using $_GET. + // @see http://drupal.org/node/1668866 + unset($_GET['destination']); } } $form_state['redirect'] = $destination;