【发布时间】:2010-08-17 21:11:32
【问题描述】:
我正在使用 nodeapi update 更新一个节点,但是我需要在幕后做更多的事情,这需要我知道一个字段的旧值/有没有办法我可以在之前获得一个字段的旧值它被覆盖了。
【问题讨论】:
我正在使用 nodeapi update 更新一个节点,但是我需要在幕后做更多的事情,这需要我知道一个字段的旧值/有没有办法我可以在之前获得一个字段的旧值它被覆盖了。
【问题讨论】:
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']);
}
update 被称为$node 对象已更新。您可能对presave 更感兴趣,它在验证后检查节点,或者validate,它在验证前检查它;在保存新的$node 对象之前,$ops 都会触发。
【讨论】:
$form_state['values'] 包含新值,但在 $form 内部有旧值(#default_value 索引)。请参阅taxonomy_overview_vocabularies_submit,但它不使用默认值。