创建新内容后如何重定向 Drupal 用户 [英] How can I redirect a Drupal user after they create new content

查看:18
本文介绍了创建新内容后如何重定向 Drupal 用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户创建一段新内容后重定向他们,而不是将他们定向到内容的查看"页面.

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.然后,您可以添加一个新的提交函数,以便在提交表单时执行.在此提交处理程序中,设置重定向路径.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆