function content_lock_form_alter in Content locking (anti-concurrent editing) 6
Same name and namespace in other branches
- 8.2 content_lock.module \content_lock_form_alter()
- 8 content_lock.module \content_lock_form_alter()
- 6.2 content_lock.module \content_lock_form_alter()
- 7.3 content_lock.module \content_lock_form_alter()
- 7 content_lock.module \content_lock_form_alter()
- 7.2 content_lock.module \content_lock_form_alter()
Implementation of hook_form_alter().
File
- ./
content_lock.module, line 155 - Allows users to lock documents for modification.
Code
function content_lock_form_alter(&$form, $form_state, $form_id) {
global $user;
$node = $form['#node'];
$nid = $form['nid']['#value'];
/** ******************* General preconditions for locking ***************** */
// Veto-API. Let other modules veto the locking - so force skiping out of any conditions they want
// We will use | logic, so if any module denies locking - we deny
// Be sure to noticte that content_lock also implements this api for his own vetos!
$skip_lock = FALSE;
// no veto yet
$result = module_invoke_all('content_lock_skip_locking', $node, $form_id, $form, $form_state);
foreach ($result as $bool) {
if (is_bool($bool)) {
$skip_lock = $skip_lock | $bool;
}
}
if ($skip_lock == FALSE) {
// if we should lock or already have been locked, load the unload js. Dont use
// form alter but rather after build, so it works even for previews
if (variable_get('content_lock_unload_js', true)) {
$form['#after_build'][] = '_content_lock_add_unload_js';
}
// Add some minor things to the form
_content_lock_add_nodeadministration($form, $form_state, $form_id);
// Adding cancel button, if configured
if (variable_get('content_lock_admin_cancelbutton', true)) {
_content_lock_add_cancelbutton($form, $form_state, $form_id);
}
// If we are handling a preview, skip locking
if ($form_state['rebuild'] == TRUE) {
// We dont need anything here right now
}
else {
if ($form_state['submitted'] === FALSE) {
// Finally set the lock if everthing passed.
if (content_lock_node($nid, $user->uid) == false) {
// could not lock node, its locked by someone else
drupal_goto("node/{$nid}");
}
}
}
// else if($form_state['submitted'] === TRUE)
// if it is a submission, we would not need to lock once again, as we had before.
// as nodeapi insert/update are not called on preview, the node should stay locked until saved or canceled.
}
}