这是我最近遇到的一个问题,所以我将添加一个“更完整”版本的 Mark Weitz 的答案,它确实有效。
首先,您需要为您键入的内容更改节点形式
//Implements hook_form_alter()
function MYMODULE_form_alter(&$form, &$form_state, $form_id){
//Check form is the node add/edit form for the required content type
if($form_id == "MYCONTENTTYPE_node_form"){
//Append our custom validation function to the forms validation array
//Note; We must use array_unshift so our function is called first.
array_unshift($form['#validate'], 'my_custom_validation_function');
}
}
现在要定义自定义验证函数,它将修复错误:
“此页面上的内容要么已被其他用户修改,要么您已经使用此表单提交了修改。因此,您的更改无法保存。”
//Our custom validation function
function my_custom_validation_function($form, &$form_state){
//Drupal somewhere in this validation chain will check our $form_state
//variable for when it thinks the node in question was last changed,
//it then determins when the node was actually changed and if the $form_state
//value is less than the drupal value it throws the 'Cant edit' error.
//To bypass this we must update our $form_state changed value to match the actual
//last changed value. Simple stuff really...
//Lets do the above ^^
$form_state['values']['changed'] = node_last_changed($form_state['values']['nid']);
//Any other extra validations you want to do go here.
}
显然,这并非没有风险,因为现在我们选择的内容类型人们能够覆盖彼此的工作。假设他们正在同时编辑节点。