You are here

function content_lock_content_lock_node_lockable in Content locking (anti-concurrent editing) 7

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

Implement our own hook_content_lock_node_lockable().

File

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

Code

function content_lock_content_lock_node_lockable($node) {
  static $lockable = array();

  // To catch the case where the user is changing the input format,
  // we store the original input format. Remember that not all nodes
  // store formats in the same way nor even have formats (#1183678).
  $format = '';
  if (!empty($node->body[$node->language][0]['format'])) {
    $format = $node->body[$node->language][0]['format'];
  }
  if (!empty($node->content_lock_old_format)) {
    $format = $node->content_lock_old_format;
  }

  // Check for a cache hit
  if (isset($lockable[$format][$node->nid])) {
    return $lockable[$format][$node->nid];
  }
  $types = array_filter(variable_get('content_lock_allowed_node_types', array()));

  // Let other modules modify our blacklist
  drupal_alter('content_lock_node_type_blacklist', $types, $node);
  $formats = array_filter(variable_get('content_lock_allowed_formats', array()));
  $lockable[$format][$node->nid] = FALSE;

  // Determine if the node is of a lockable content type or text format.
  if ((empty($types) || in_array($node->type, $types)) && (empty($formats) || in_array($format, $formats))) {
    $lockable[$format][$node->nid] = TRUE;
  }
  return $lockable[$format][$node->nid];
}