You are here

function content_lock_node_ajax_callback in Content locking (anti-concurrent editing) 7.3

Same name and namespace in other branches
  1. 7.2 content_lock.module \content_lock_node_ajax_callback()

AJAX callback to lock a node manually.

Parameters

object $node:

The node to lock.

string $token: The CSRF token.

1 string reference to 'content_lock_node_ajax_callback'
content_lock_menu in ./content_lock.module
Implements hook_menu().

File

includes/content_lock.ajax.inc, line 17
content_lock.ajax.inc

Code

function content_lock_node_ajax_callback($entity_id, $token, $ajax = NULL) {
  $is_ajax = $ajax === 'ajax';
  if (!drupal_valid_token($token, $entity_id)) {
    return MENU_ACCESS_DENIED;
  }
  global $user;

  // Lock current entity.
  content_lock_locking($entity_id, $user->uid);

  // Add the javascript that unlocks the node when the user navigates away
  // from the page.
  $form = array(
    'nid' => array(
      '#value' => $entity_id,
    ),
  );
  content_lock_js($form);
  if ($is_ajax) {
    $commands = array();
    $commands[] = ajax_command_remove('div.messages');
    $commands[] = ajax_command_before('#block-system-main', theme('status_messages'));
    ajax_deliver(array(
      '#type' => 'ajax',
      '#commands' => $commands,
    ));
  }
  else {
    drupal_set_message(t('The content is locked now.'));
    drupal_goto();
  }
}