我想重定向通过用户登录块登录的用户。我所拥有的是一个包含以下代码的模块:
附录,3.9.2011,15:30h:根据 kiamlaluno 的建议更改了代码。
附录,3.9.2011,17:08h:小修复:将节点/管理员更改为管理员。
附录,3.9.2011,17:24h:已删除[]
-> 代码现在是这样工作的,但不要忘记更改 DB 中的模块优先级。
function _MYMODULE_user_login_submit($form, &$form_state) {
global $user;
if ($user->uid == 1) {
$form_state['redirect'] = 'admin';
} elseif ($user->uid) {
$form_state['redirect'] = 'node/add/image';
return;
}
}
/**
* Modifies the outfit and behaviour of the user login block.
*/
function MYMODULE_form_user_login_block_alter(&$form, $form_state) {
unset($form['#action']);
// removes the forgot password and register links
$form['links'] = array();
// Redirects the user to the image upload page after login
// This cannot be done by a rule, the rule based redirect is only
// working for the login page not the user login block.
$form['#submit'] = array('_MYMODULE_user_login_submit');
}
它不会重定向用户;似乎_MYMODULE_user_login_submit()只是被忽略了。
我已经知道的:
- 我不能使用规则/触发器,因为我没有通过登录页面登录,而是通过用户登录块登录
- 总是说:“在帖子上使用 logintoboggan”,但我只有“注册时”和“确认时”的重定向选项,但我需要“身份验证”或“登录后”。
- 反正我不想用更多的模块,我更喜欢几行PHP。