function content_lock_locking in Content locking (anti-concurrent editing) 7.3
Try to lock a document for editing.
If the lock exists, a new AJAX unlock key is created to combat AJAX unlocks during page reloads. See http://drupal.org/node/1049708.
Parameters
int $nid: A node id.
int $uid: The user id to lock the node for.
bool $quiet: Suppress any normal user messages.
Return value
bool FALSE, if a document has already been locked by someone else.
3 calls to content_lock_locking()
- content_lock_node_ajax_callback in includes/
content_lock.ajax.inc - AJAX callback to lock a node manually.
- content_lock_node_form_handler in includes/
content_lock.node.inc - Node and node revision handler.
- content_lock_node_validate in ./
content_lock.module - Implements hook_node_validate().
File
- ./
content_lock.module, line 381
Code
function content_lock_locking($entity_id, $uid, $entity_type = 'node', $quiet = FALSE) {
// Load module inc file.
module_load_include('inc', 'content_lock', 'includes/content_lock.func');
// Check locking status.
$lock = content_lock_fetch_lock($entity_id, $entity_type);
// No lock yet.
if ($lock === FALSE || !is_object($lock)) {
// Save locking into database.
_content_lock_locking_save($entity_id, $uid, $entity_type);
if (content_lock_verbose() && !$quiet) {
drupal_set_message(t('This document is now locked against simultaneous editing.'), 'status', FALSE);
}
// Post locking hook.
module_invoke_all('content_lock_locked', $entity_id, $uid, $entity_type);
// Send success flag.
return TRUE;
}
else {
// Currently locking by other user.
if ($lock->uid != $uid) {
$message = content_lock_lock_owner($lock);
// Higher permission user can unblock.
if (user_access('administer checked out documents')) {
$url = 'admin/content/content_lock/release/' . $entity_id;
$token = content_lock_get_release_token($entity_id);
$message .= '<br />';
$message .= t('Click !here to release the lock right now.', array(
'!here' => l(t('here'), $url, array(
'query' => array(
'token' => $token,
'destination' => $_GET['q'],
),
)),
));
}
// Send message.
drupal_set_message($message, 'warning', FALSE);
// Return FALSE flag.
return FALSE;
}
else {
// Save locking into database.
_content_lock_locking_save($entity_id, $uid, $entity_type);
// Locked by current user.
if (content_lock_verbose() && !$quiet) {
drupal_set_message(t('This document is now locked by you against simultaneous editing.'), 'status', FALSE);
}
// Send success flag.
return TRUE;
}
}
}