Skip to content

Commit 67a7f17

Browse files
snufkinBalazs Dianiska
authored andcommitted
Issue #2619262 by epicflux, snufkin: Allow Modules to Alter $gotourl on User Logout
1 parent 6e92be6 commit 67a7f17

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

simplesamlphp_auth.api.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,39 @@ function hook_simplesamlphp_auth_pre_login($attributes, $ext_user) {
7070
exit();
7171
}
7272
}
73+
74+
/**
75+
* Allow modules to change the url passed to simplesamlphp during logout.
76+
*
77+
* Called when a user logs out of Drupal.
78+
*
79+
* @param string $gotourl
80+
* The url to be passed to simplesamlphp.
81+
* @param object $account
82+
* The user being logged out.
83+
*/
84+
function hook_simplesamlphp_auth_logout_gotourl_alter(&$gotourl, $account) {
85+
// Example of reacting to a value on the account.
86+
if ($account->field_example == 'example_value') {
87+
$gotourl = url(
88+
'thanks-for-stopping-by',
89+
array(
90+
'absolute' => TRUE,
91+
)
92+
);
93+
}
94+
95+
// Example of adding the destination value to the redirect URL.
96+
if (isset($_GET['destination'])) {
97+
// Ensure our redirect URL is absolute.
98+
$redirect_url = url(
99+
$_GET['destination'],
100+
array(
101+
'absolute' => TRUE,
102+
)
103+
);
104+
105+
// Add our redirect URL as a querystring to the full URL.
106+
$gotourl = $gotourl . '?redirect=' . drupal_encode_path($redirect_url);
107+
}
108+
}

simplesamlphp_auth.module

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ function simplesamlphp_auth_user_logout($account) {
250250
$gotourl = variable_get('simplesamlphp_auth_logoutgotourl', '');
251251
}
252252

253+
// Allow modules to alter $gotourl.
254+
drupal_alter('simplesamlphp_auth_logout_gotourl', $gotourl, $account);
255+
253256
$_simplesamlphp_auth_as->logout($gotourl);
254257

255258
}

0 commit comments

Comments
 (0)