编程语言
首页 > 编程语言> > php – 节点更新:获取旧值

php – 节点更新:获取旧值

作者:互联网

我正在使用nodeapi更新更新节点,但是我需要在幕后进行更多操作,这需要我知道字段的旧值/是否有一种方法可以在覆盖之前获取字段的旧值.

解决方法:

编辑

hook_nodeapi()只对新的$node对象起作用,所以我之前的回答对你没用.相反,您需要在提交时访问节点.为此,您需要注册自己的提交处理程序,该提交程序将在提交节点表单时被调用.它可以让您访问当前值和新值:

function test_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id === 'contenttype_node_form') { // Replace contenttype
    $form['#submit'][] = 'test_submit'; // Add a submit handler
  }
}

function test_submit($form, &$form_state) {
   // Load the current node object
  $node = node_load($form_state['values']['nid']); 

  // Display the current node object's values
  dsm($node);

  // Display the submitted values
  dsm($form_state['values']);
}

更新称为$node对象已更新.您可能对presave更感兴趣,它在验证后检查节点,或验证,在验证之前检查它;两个$ops在保存新的$node对象之前触发.

标签:php,drupal,drupal-6
来源: https://codeday.me/bug/20190705/1383837.html