在创建新内容后,如何重定向Drupal用户 [英] How can I redirect a Drupal user after they create new content
问题描述
我想在用户创建新内容后重定向他们,而不是将他们定向到该内容的查看页面。
I want to redirect my users after they create a piece of new content, instead of directing them to the 'view' page for the content.
我已经看到了提到使用hook_alter之类的东西,但是我真的对drupal陌生,甚至不知道这意味着什么?
I have seen mention of using hook_alter or something, but I'm really new to drupal and not even sure what that means?
谢谢!
推荐答案
正如您所提到的,您是Drupal的新手,我建议您看一下规则模块。您可以为内容已保存/更新添加触发器,并添加操作以将用户重定向到特定页面。
As you mention that you are new to Drupal, I'd suggest to take a look at the Rules module. You can add a trigger on for content has been saved/updated and add an action, to redirect the user to a specific page.
不过,您可以使用form_alter钩子在轻量级的自定义模块中执行相同的操作。
You can however do the same in a light weight custom module using a form_alter hook.
首先,找到表单的表单ID。对于节点表单,它是[node-type] _node_form。
然后,您可以添加一个新的Submit函数,以便在提交表单时执行该函数。在此提交处理程序中,设置重定向路径。
First, find the form ID of the form. For node forms, it's the [node-type]_node_form. Then, you can add a new submit function to be executed when the form is submitted. In this submit handler, set the redirect path.
请参见本指南,其中介绍了如何创建模块。
您的模块代码如下所示:
See this guide on a basic how-to on creating a module. Your module code would be something like belows:
<?php
function mymodule_mytype_node_form_alter(&$form, &$form_state) {
$form['#submit'][] = 'mymodule_node_submit_do_redirect';
}
function mymodule_node_submit_do_redirect($form, &$form_state) {
$form_state['redirect'] = 'my_custom_destination';
}
一种简单得多的方法是在节点表单的URL中设置目标。
例如,如果您打开 http://example.com/node/add/mytype?destination=my_custom_destination
,您将被重定向到该URL,而不是节点视图页面。
A much much simpler approach is to set the destination in the node form's URL.
For example, if you opened http://example.com/node/add/mytype?destination=my_custom_destination
, you will be redirected to that URL instead of the node view page.
这篇关于在创建新内容后,如何重定向Drupal用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!