You are here

function content_lock_content_lock_skip_locking in Content locking (anti-concurrent editing) 7.2

Same name and namespace in other branches
  1. 6.2 content_lock.module \content_lock_content_lock_skip_locking()
  2. 6 content_lock.module \content_lock_content_lock_skip_locking()
  3. 7.3 content_lock.module \content_lock_content_lock_skip_locking()
  4. 7 content_lock.module \content_lock_content_lock_skip_locking()

Implements our own skip_locking api to implement our logic to skip locks.

File

./content_lock.module, line 385
Allows users to lock documents for modification.

Code

function content_lock_content_lock_skip_locking($node, $form_id, $form, $form_state) {
  global $user;
  $nid = empty($form['nid']['#value']) ? NULL : $form['nid']['#value'];

  // Support node revision by not requiring the form to have an 'nid' key.
  if (empty($nid) && $form_id == 'node_revision_revert_confirm' && !empty($form['#node_revision'])) {
    $nid = $node->nid;
  }

  // Locked node types. Do not mix this up with the content_types you can
  // chose on the admin form of content lock
  // this types are forced due to disfunctionality.
  // We are not allowed to lock on users form edit, as it
  // always returns to the edit form.
  $node_type_blacklist = array(
    'user' => TRUE,
  );

  // Form ids listed here will not be locked.
  // Do not lock on comment forms.
  $form_id_blacklist = array(
    'comment_form' => TRUE,
  );

  // Add the node-type administration.
  if ($node != NULL) {
    $form_id_blacklist['node_type_form'] = TRUE;
  }

  // Let other modules modify our blacklist.
  drupal_alter('content_lock_form_id_blacklist', $form_id_blacklist, $node);
  if ($node == NULL || empty($nid) || !empty($node_type_blacklist[$node->type]) || !empty($form_id_blacklist[$form_id]) || $user->uid <= 0 || !user_access('check out documents') || $form_id != $node->type . '_node_form' && $form_id != 'node_revision_revert_confirm') {

    // Preconditions failed, skip the lock.
    return TRUE;
  }

  // Check if the current node type and format type is configured to be locked
  // $node->content_lock_old_format has been set in content_lock_form_alter().
  if (!_content_lock_is_lockable_node($node)) {

    // It should not be locked, so skip the lock.
    return TRUE;
  }

  // We have no veto, so lock the node.
  return FALSE;
}