Issue #1807632 by dawehner, damiankloip: Fixed Redirect after editing via contextual links leads to errors.
parent
fb4926ca4b
commit
7427e625e2
|
@ -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.');
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue