如何获取以钩子形式 alter 定义的提交处理程序中的节点 id

发布于 2024-12-09 09:03:32 字数 425 浏览 0 评论 0原文

是否有不同的钩子可以用来获取提交的新节点的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不必了 2024-12-16 09:03:32

此时节点实际上尚未保存,您需要实现 hook_node_insert

function dc_project_management_node_insert($node) {
  $nid = $node->nid;
}

The node hasn't actually been saved at that point, you need to implement hook_node_insert:

function dc_project_management_node_insert($node) {
  $nid = $node->nid;
}
征﹌骨岁月お 2024-12-16 09:03:32

检索节点 ID 的唯一方法是使用 hook_node_insert。但是,如果您希望从此挂钩内部修改 node 对象,则必须将更改通知 Drupal,否则更改将不会进入数据库事务并会丢失。

修改完节点后,调用 field_attach_updates('node', $node)。例如:

function mymodule_node_insert($node){
    $node->field_myfield['und'][0]['value'] = 'a new value';

    field_attach_update('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 the node 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:

function mymodule_node_insert($node){
    $node->field_myfield['und'][0]['value'] = 'a new value';

    field_attach_update('node', $node);
}

See http://timonweb.com/how-save-yourself-some-hair-when-manipulating-node-fields for more information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文