', array('fragment' => 'overlay=' . $current_path));
}
if (isset($_GET['render']) && $_GET['render'] == 'overlay') {
@@ -343,7 +344,7 @@ function overlay_user_dismiss_message() {
$account->save();
drupal_set_message(t('The message has been dismissed. You can change your overlay settings at any time by visiting your profile page.'));
// Destination is normally given. Go to the user profile as a fallback.
- drupal_goto('user/' . $user->uid . '/edit');
+ return new RedirectResponse('user/' . $user->uid . '/edit');
}
/**
diff --git a/core/modules/search/search.pages.inc b/core/modules/search/search.pages.inc
index c940223..4966032 100644
--- a/core/modules/search/search.pages.inc
+++ b/core/modules/search/search.pages.inc
@@ -5,6 +5,8 @@
* User page callbacks for the search module.
*/
+use Drupal\Core\Utility\RedirectResponse;
+
/**
* Menu callback; presents the search form and/or search results.
*
@@ -40,7 +42,7 @@ function search_view($module = NULL, $keys = '') {
if ($keys) {
$path .= '/' . $keys;
}
- drupal_goto($path);
+ return new RedirectResponse($path);
}
// Default results output is an empty string.
diff --git a/core/modules/shortcut/shortcut.admin.inc b/core/modules/shortcut/shortcut.admin.inc
index 3345c59..0675d71 100644
--- a/core/modules/shortcut/shortcut.admin.inc
+++ b/core/modules/shortcut/shortcut.admin.inc
@@ -6,6 +6,7 @@
*/
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
+use Drupal\Core\Utility\RedirectResponse;
/**
* Form callback: builds the form for switching shortcut sets.
@@ -690,7 +691,7 @@ function shortcut_link_add_inline($shortcut_set) {
else {
drupal_set_message(t('Unable to add a shortcut for %title.', array('%title' => $link['link_title'])));
}
- drupal_goto();
+ return new RedirectResponse();
}
throw new AccessDeniedHttpException();
diff --git a/core/modules/simpletest/simpletest.pages.inc b/core/modules/simpletest/simpletest.pages.inc
index a98b445..b6a6c1c 100644
--- a/core/modules/simpletest/simpletest.pages.inc
+++ b/core/modules/simpletest/simpletest.pages.inc
@@ -5,6 +5,8 @@
* Page callbacks for simpletest module.
*/
+use Drupal\Core\Utility\RedirectResponse;
+
/**
* List tests arranged in groups that can be selected and run.
*/
@@ -208,8 +210,7 @@ function simpletest_result_form($form, &$form_state, $test_id) {
$results = array();
if (is_numeric($test_id) && !$results = simpletest_result_get($test_id)) {
drupal_set_message(t('No test results to display.'), 'error');
- drupal_goto('admin/config/development/testing');
- return $form;
+ return new RedirectResponse('admin/config/development/testing');
}
// Load all classes and include CSS.
diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc
index 45ad10e..9394a65 100644
--- a/core/modules/system/system.admin.inc
+++ b/core/modules/system/system.admin.inc
@@ -8,6 +8,7 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
+use Drupal\Core\Utility\RedirectResponse;
/**
* Menu callback; Provide the administration overview page.
@@ -280,7 +281,7 @@ function system_theme_enable() {
else {
drupal_set_message(t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
}
- drupal_goto('admin/appearance');
+ return new RedirectResponse('admin/appearance');
}
throw new AccessDeniedHttpException();
}
@@ -308,7 +309,7 @@ function system_theme_disable() {
else {
drupal_set_message(t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
}
- drupal_goto('admin/appearance');
+ return new RedirectResponse('admin/appearance');
}
throw new AccessDeniedHttpException();
}
@@ -355,7 +356,7 @@ function system_theme_default() {
else {
drupal_set_message(t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
}
- drupal_goto('admin/appearance');
+ return new RedirectResponse('admin/appearance');
}
throw new AccessDeniedHttpException();
}
@@ -1329,7 +1330,7 @@ function system_modules_uninstall_validate($form, &$form_state) {
// Form submitted, but no modules selected.
if (!count(array_filter($form_state['values']['uninstall']))) {
drupal_set_message(t('No modules selected.'), 'error');
- drupal_goto('admin/modules/uninstall');
+ return new RedirectResponse('admin/modules/uninstall');
}
}
@@ -1646,7 +1647,7 @@ function system_run_cron_submit($form, &$form_state) {
drupal_set_message(t('Cron run failed.'), 'error');
}
- drupal_goto('admin/config/system/cron');
+ return new RedirectResponse('admin/config/system/cron');
}
/**
@@ -2287,7 +2288,7 @@ function system_run_cron() {
drupal_set_message(t('Cron run failed.'), 'error');
}
- drupal_goto('admin/reports/status');
+ return new RedirectResponse('admin/reports/status');
}
/**
@@ -3023,7 +3024,7 @@ function system_actions_manage_form_submit($form, &$form_state) {
*/
function system_actions_configure($form, &$form_state, $action = NULL) {
if ($action === NULL) {
- drupal_goto('admin/config/system/actions');
+ return new RedirectResponse('admin/config/system/actions');
}
$actions_map = actions_actions_map(actions_list());
@@ -3170,7 +3171,7 @@ function system_action_delete_orphans_post($orphaned) {
*/
function system_actions_remove_orphans() {
actions_synchronize(TRUE);
- drupal_goto('admin/config/system/actions/manage');
+ return new RedirectResponse('admin/config/system/actions/manage');
}
/**
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index a76e3ae..a6091a1 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -7,6 +7,7 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
+use Drupal\Core\Utility\RedirectResponse;
/**
* Maximum age of temporary files in seconds.
@@ -1911,8 +1912,8 @@ function _system_themes_access($theme) {
* or to call system_authorized_init() and then redirect to authorize.php,
* using the URL from system_authorized_get_url(). Redirecting yourself is
* necessary when your authorized operation is being triggered by a form
- * submit handler, since calling drupal_goto() in a submit handler is a bad
- * idea, and you should instead set $form_state['redirect'].
+ * submit handler, since calling new RedirectResponse in a submit handler is a
+ * bad idea, and you should instead set $form_state['redirect'].
*
* Once the SESSION is setup for the operation and the user is redirected to
* authorize.php, they will be prompted for their connection credentials (core
@@ -1999,7 +2000,7 @@ function system_authorized_batch_processing_url() {
*/
function system_authorized_run($callback, $file, $arguments = array(), $page_title = NULL) {
system_authorized_init($callback, $file, $arguments, $page_title);
- drupal_goto(system_authorized_get_url());
+ return new RedirectResponse(system_authorized_get_url());
}
/**
@@ -3217,7 +3218,7 @@ function system_admin_compact_mode() {
*/
function system_admin_compact_page($mode = 'off') {
user_cookie_save(array('admin_compact_mode' => ($mode == 'on')));
- drupal_goto();
+ return new RedirectResponse();
}
/**
@@ -3624,7 +3625,7 @@ function system_goto_action_submit($form, $form_state) {
* @ingroup actions
*/
function system_goto_action($entity, $context) {
- drupal_goto(token_replace($context['url'], $context));
+ return new RedirectResponse(token_replace($context['url'], $context));
}
/**
diff --git a/core/modules/system/tests/modules/common_test/common_test.module b/core/modules/system/tests/modules/common_test/common_test.module
index 187fee5..6bc13dd 100644
--- a/core/modules/system/tests/modules/common_test/common_test.module
+++ b/core/modules/system/tests/modules/common_test/common_test.module
@@ -5,6 +5,8 @@
* Helper module for the Common tests.
*/
+use Drupal\Core\Utility\RedirectResponse;
+
/**
* Implements hook_menu().
*/
@@ -35,8 +37,7 @@ function common_test_menu() {
);
$items['common-test/drupal_goto/redirect_fail'] = array(
'title' => 'Drupal Goto Failure',
- 'page callback' => 'drupal_goto',
- 'page arguments' => array('common-test/drupal_goto/fail'),
+ 'page callback' => 'common_test_drupal_goto_redirect_fail',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
@@ -62,28 +63,35 @@ function common_test_menu() {
}
/**
- * Redirect using drupal_goto().
+ * Redirect using RedirectResponse.
*/
function common_test_drupal_goto_redirect() {
- drupal_goto('common-test/drupal_goto');
+ return new RedirectResponse('common-test/drupal_goto');
+}
+
+/**
+ * Redirect using RedirectResponse.
+ */
+function common_test_drupal_goto_redirect_fail() {
+ return new RedirectResponse('common-test/drupal_goto/fail');
}
/**
- * Redirect using drupal_goto().
+ * Redirect using RedirectResponse.
*/
function common_test_drupal_goto_redirect_advanced() {
- drupal_goto('common-test/drupal_goto', array('query' => array('foo' => '123')), 301);
+ return new RedirectResponse('common-test/drupal_goto', array('query' => array('foo' => '123')), 301);
}
/**
- * Landing page for drupal_goto().
+ * Landing page for RedirectResponse.
*/
function common_test_drupal_goto_land() {
print "drupal_goto";
}
/**
- * Fail landing page for drupal_goto().
+ * Fail landing page for RedirectResponse.
*/
function common_test_drupal_goto_land_fail() {
print "drupal_goto_fail";
diff --git a/core/modules/system/tests/modules/system_test/system_test.module b/core/modules/system/tests/modules/system_test/system_test.module
index 444d54d..f7f69ef 100644
--- a/core/modules/system/tests/modules/system_test/system_test.module
+++ b/core/modules/system/tests/modules/system_test/system_test.module
@@ -1,5 +1,7 @@
uid . '/edit');
+ return new RedirectResponse('user/' . $GLOBALS['user']->uid . '/edit');
}
}
}
@@ -1866,7 +1867,7 @@ function user_login($form, &$form_state) {
// If we are already logged on, go to the user page instead.
if ($user->uid) {
- drupal_goto('user/' . $user->uid);
+ return new RedirectResponse('user/' . $user->uid);
}
// Display login form:
@@ -3051,7 +3052,7 @@ function user_multiple_cancel_confirm($form, &$form_state) {
drupal_set_message($message, $redirect ? 'error' : 'warning');
// If only user 1 was selected, redirect to the overview.
if ($redirect) {
- drupal_goto('admin/people');
+ return new RedirectResponse('admin/people');
}
}
@@ -3512,7 +3513,7 @@ function user_register_form($form, &$form_state) {
// If we aren't admin but already logged on, go to the user page instead.
if (!$admin && $user->uid) {
- drupal_goto('user/' . $user->uid);
+ return new RedirectResponse('user/' . $user->uid);
}
$form['#user'] = entity_create('user', array());
diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc
index b568f66..4976a82 100644
--- a/core/modules/user/user.pages.inc
+++ b/core/modules/user/user.pages.inc
@@ -9,6 +9,7 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;
+use Drupal\Core\Utility\RedirectResponse;
/**
* Menu callback; Retrieve a JSON object containing autocomplete suggestions for existing users.
@@ -115,7 +116,7 @@ function user_pass_reset($form, &$form_state, $uid, $timestamp, $hashed_pass, $a
drupal_set_message(t('The one-time login link you clicked is invalid.'));
}
}
- drupal_goto();
+ return new RedirectResponse();
}
else {
// Time out, in seconds, until login URL expires. Defaults to 24 hours =
@@ -128,7 +129,7 @@ function user_pass_reset($form, &$form_state, $uid, $timestamp, $hashed_pass, $a
// No time out for first time login.
if ($account->login && $current - $timestamp > $timeout) {
drupal_set_message(t('You have tried to use a one-time login link that has expired. Please request a new one using the form below.'));
- drupal_goto('user/password');
+ return new RedirectResponse('user/password');
}
elseif ($account->uid && $timestamp >= $account->login && $timestamp <= $current && $hashed_pass == user_pass_rehash($account->pass, $timestamp, $account->login)) {
// First stage is a confirmation form, then login
@@ -143,7 +144,7 @@ function user_pass_reset($form, &$form_state, $uid, $timestamp, $hashed_pass, $a
// Let the user's password be changed without the current password check.
$token = drupal_hash_base64(drupal_random_bytes(55));
$_SESSION['pass_reset_' . $user->uid] = $token;
- drupal_goto('user/' . $user->uid . '/edit', array('query' => array('pass-reset-token' => $token)));
+ return new RedirectResponse('user/' . $user->uid . '/edit', array('query' => array('pass-reset-token' => $token)));
}
else {
$form['message'] = array('#markup' => t('This is a one-time login for %user_name and will expire on %expiration_date.
Click on this button to log in to the site and change your password.
', array('%user_name' => $account->name, '%expiration_date' => format_date($timestamp + $timeout))));
@@ -156,7 +157,7 @@ function user_pass_reset($form, &$form_state, $uid, $timestamp, $hashed_pass, $a
}
else {
drupal_set_message(t('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.'));
- drupal_goto('user/password');
+ return new RedirectResponse('user/password');
}
}
else {
@@ -180,7 +181,7 @@ function user_logout() {
// Destroy the current session, and reset $user to the anonymous user.
session_destroy();
- drupal_goto();
+ return new RedirectResponse();
}
/**
@@ -482,7 +483,7 @@ function user_cancel_confirm($account, $timestamp = 0, $hashed_pass = '') {
}
else {
drupal_set_message(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'));
- drupal_goto("user/$account->uid/cancel");
+ return new RedirectResponse("user/$account->uid/cancel");
}
}
throw new AccessDeniedHttpException();