You are here

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

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

File

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

Code

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

  // Locked node types. Dont mix this up with the content_types you can chose on the admin form of content lock
  // this types are forced due to disfunctionality
  $node_type_blacklist = array(
    'user' => TRUE,
  );

  // Form ids listed here will not be locked
  $form_id_blacklist = array(
    'comment_form' => TRUE,
  );
  if ($node != NULL) {
    $form_id_blacklist['node_type_form'] = TRUE;

    // add the node-type administration
  }

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

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

  /* **************** Restore the node format ****************************** */

  // _content_lock_is_lockable_node() needs to know the original
  // node format.
  // TODO: this stuff pretty sure on the wrong place here. On preview + no validation errors this should break
  // due to form rebuild and missing values in $form_state['values'] .. only $form['#node'] is preserved in this case
  $old_format = $node->format;
  if (!empty($form_state['values']['content_lock_old_format'])) {
    $old_format = $form_state['values']['content_lock_old_format'];
  }
  $form['content_lock_old_format'] = array(
    '#type' => 'hidden',
    '#value' => $old_format,
  );

  // Needs to be manually set before first form submission.
  // We set this in the $node-> namespace because content_lock_nodeapi()
  // doesn't see $form_state['values'].
  $node->content_lock_old_format = $old_format;

  // Check if the current node type and format type is configured to be locked
  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;
}