Drupal节点创建-创建后返回原点
我设置了有机群组,并且在这些群组中允许用户发布某些内容。 我想要做的是,当您在有机组内创建节点时,它会自动默认返回到该组的首页,或者我用来创建节点的同一页面。
目前它默认为节点视图页面。我假设必须有一种方法来添加某种代码,以便在节点创建后它默认返回到其原始位置。 IE 创建节点的页面。
谢谢:)
更新:得到以下内容,但不完全确定如何确保它从创建它的位置重定向回 GROUP 节点,
<?php
/**
* Grabs current node ID
*/
$node_nid = nid;
/**
* Implements hook_form_alter().
*/
function mod_form_alter(&$form, $form_state) {
$form['buttons']['submit']['#submit'][] = 'mod_form_finish_redirect';
unset($form['buttons']['preview']);
}
/**
* Custom submit handler. Overwrites the form redirection variable.
*/
function mod_form_finish_redirect($form, &$form_state) {
$form_state['redirect'] = '/content/<?php print $node_nid; ?>';
}
?>
I have organic groups setup and within those group users are allowed to post certain content.
What I woulkd like to do is, when you create a node inside an organic group, it automatically defaults back to frontpage of the group, or the same page that I used to create the node.
At present it defaults to the node view page.I assume there must be a way to add some kind of code so that after the node creation it defauls back to its origin. I.E. the page from where the node was created from.
thanks :)
UPDATE: Got the below, but not entirly sure how to ensure that it redirects back to the GROUP node, from where it was created,
<?php
/**
* Grabs current node ID
*/
$node_nid = nid;
/**
* Implements hook_form_alter().
*/
function mod_form_alter(&$form, $form_state) {
$form['buttons']['submit']['#submit'][] = 'mod_form_finish_redirect';
unset($form['buttons']['preview']);
}
/**
* Custom submit handler. Overwrites the form redirection variable.
*/
function mod_form_finish_redirect($form, &$form_state) {
$form_state['redirect'] = '/content/<?php print $node_nid; ?>';
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我推荐 rules 模块。规则是一个很棒的模块,它允许您执行多种工作流程,并且非常适合此目的。您可以编写一条规则,在创建指定的节点类型时触发(并包括您需要的任何其他条件)。创建节点后,您可以指定到主页的重定向操作规则。这一切都可以在没有任何代码的情况下完成。
I would recommend the rules module. Rules is a great module that allows you to do many kinds of workflow and it is perfect for this. You can write a rule that triggers when a specified node type is created (and include any other conditions you require as well). After the node is created you can specify a redirect action rule to the home page. This can all be done without any code.
规则(正如“我们爱 Drupal”所说)是一种可能性,但对于如此小的行为变化来说也是一个相当大的模块。另一种选择是编写一个实现 的自定义模块hook_form_alter 设置#redirect 值< /a> 的形式。
请记住,看到您刚刚创建的节点对于用户来说是重要的反馈。当您执行某项操作时,您希望确认您已完成任务。虽然在技术上可以按照您的要求进行操作,但这可能不利于可用性。
Rules (as 'We Love Drupal' says) is a possibility, but also quite a big module for such a small change in behavior. Another option is to write a custom module implementing hook_form_alter setting the #redirect value of the form.
Keep in mind that of seeing the node you have just created is important feedback for a user. When you perform an action, you want confirmation that you have achieved your task. While it's technically possible to do what you ask, it may be bad for usability.
我有同样的要求。规则对我有用。
I had the same requirment. Rules worked for me.