這是一個問題,我跑進最近existe,所以我會添加馬克·韋茲的答案的「更全面」版本,它確實工作。
首先,你需要改變的內容的節點形式鍵入您需要
//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.
}
顯然,這不是沒有它的風險,因爲現在我們所選擇的內容類型的人都能夠覆蓋彼此的工作。假設他們正在同時編輯節點。
小孩把這個代碼,以及如何回調它 – Rami