小智 3
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']);
}
Run Code Online (Sandbox Code Playgroud)
update称为$node对象已更新。您可能更感兴趣presave,它在验证后检查节点,或者validate,它在验证之前检查节点;两者$op都会在新$node对象保存之前触发。