自动更改节点作者

use*_*259 2 drupal drupal-7

匿名用户可以发布节点.发布节点后,用户将被重定向到注册.注册后,先前提交的节点应与新注册的用户链接.我玩规则和实体,但我无法正常工作.有任何想法吗?

chx*_*chx 5

我会写一个自定义模块(但那就是我).该模块需要实现hook_node_insert并保存nidSESSION.然后hook_user_insert它就可以做出改变.未经测试的代码:

function foo_node_insert($node) {
  $_SESSION['mynodes'][] = $node->nid;
}

function foo_user_insert($edit, $account) {
  if (!empty($_SESSION['mynodes'])) {
    foreach ($_SESSION['mynodes'] as $nid) {
      $node = node_load($nid);
      $node->uid = $account->uid;
      // This saves the revision as the current user uid but that's just what we wanted.
      node_save($node);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

编辑:别忘了 unset($_SESSION['mynodes']);