如何获取以钩子形式 alter 定义的提交处理程序中的节点 id
是否有不同的钩子可以用来获取提交的新节点的node_id?
function dc_project_management_form_bug_request_node_form_alter(&$form, &$form_state, $form_id)
{
$form['#submit'][] = 'dc_project_management_process_bug_request_milestone_submit';
}
function dc_project_management_process_bug_request_milestone_submit($form, &$form_state)
{
//NULL when submitting new node
$form_state['values']['nid'];
}
Is there a different hook I can use to get the node_id of a NEW node that is submitted?
function dc_project_management_form_bug_request_node_form_alter(&$form, &$form_state, $form_id)
{
$form['#submit'][] = 'dc_project_management_process_bug_request_milestone_submit';
}
function dc_project_management_process_bug_request_milestone_submit($form, &$form_state)
{
//NULL when submitting new node
$form_state['values']['nid'];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此时节点实际上尚未保存,您需要实现
hook_node_insert
:The node hasn't actually been saved at that point, you need to implement
hook_node_insert
:检索节点 ID 的唯一方法是使用
hook_node_insert
。但是,如果您希望从此挂钩内部修改node
对象,则必须将更改通知 Drupal,否则更改将不会进入数据库事务并会丢失。修改完节点后,调用
field_attach_updates('node', $node)
。例如:请参阅 http://timonweb.com/how -save-yourself-some-hair-when-manipulate-node-fields 了解更多信息。
The only way to retrieve the node id is to use
hook_node_insert
. However, if you wish to make modifications to thenode
object from inside this hook, you must notify Drupal of the alteration, otherwise the changes won't make it into the database transaction and will be lost.After you're done modifying the node, call
field_attach_updates('node', $node)
. For example:See http://timonweb.com/how-save-yourself-some-hair-when-manipulating-node-fields for more information.