function content_lock_node_validate in Content locking (anti-concurrent editing) 7.3
Same name and namespace in other branches
- 7 content_lock.module \content_lock_node_validate()
- 7.2 content_lock.module \content_lock_node_validate()
Implements hook_node_validate().
File
- ./
content_lock.module, line 524
Code
function content_lock_node_validate($node, $form, &$form_state) {
// Only locking existing nodes with NID.
if (!isset($node->nid)) {
return;
}
if (content_lock_is_lockable($node) && user_access('check out documents')) {
global $user;
// Existing node. Check if we still own the lock.
if ($lock = content_lock_fetch_lock($node->nid)) {
if ($lock->uid != $user->uid) {
// Lock is no longer ours.
form_set_error('changed', t('Your lock has been removed!') . '<br />' . content_lock_lock_owner($lock) . '<br />' . t('You can still save the content if this user aborts the edit operation without saving changes.'));
}
}
else {
// Node is not locked. Try to re-lock if node is unchanged.
if (node_last_changed($node->nid) > $node->changed || !content_lock_locking($node->nid, $user->uid)) {
form_set_error('alsochanged', t('Your lock has been removed due to inactivity or by an administrator. Failed to regain the lock since the document has been changed since. Please !discard.', array(
'!discard' => l(t('discard your changes'), 'node/' . $node->nid),
)));
}
}
}
}