You are here

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

Same name and namespace in other branches
  1. 6.2 content_lock.module \_content_lock_add_cancelbutton()
  2. 6 content_lock.module \_content_lock_add_cancelbutton()
  3. 7.2 content_lock.module \_content_lock_add_cancelbutton()
1 call to _content_lock_add_cancelbutton()
content_lock_form_alter in ./content_lock.module
Implementation of hook_form_alter().

File

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

Code

function _content_lock_add_cancelbutton(&$form, $form_state, $form_id) {

  // If we're on the node form
  $node = empty($form['#node']) ? NULL : $form['#node'];
  $nid = empty($form['nid']['#value']) ? NULL : $form['nid']['#value'];
  if (!empty($form['#node_revision'])) {
    $node = $form['#node_revision'];
    $nid = $node->nid;
  }
  if (!empty($node) && !empty($nid) && ($form_id == $node->type . '_node_form' || $form_id == 'node_revision_revert_confirm')) {

    // revert node
    if ($form_id == 'node_revision_revert_confirm') {

      /* hijack the default cancel link to become a lock-releasing link */
      $destination = 'node/' . $nid . '/revisions';
      if (!empty($form['actions']['cancel']['#href'])) {
        $destination = $form['actions']['cancel']['#href'];
      }
      $form['actions']['cancel']['#href'] = 'admin/content/' . $nid . '/content_lock/releaseown';
      $form['actions']['cancel'] += array(
        '#options' => array(),
      );
      $form['actions']['cancel']['#options'] += array(
        'query' => array(
          'token' => content_lock_get_release_token($nid),
          'destination' => $destination,
        ),
      );
    }
    else {
      if ($node->nid) {
        $form['actions']['cancel'] = array(
          '#type' => 'button',
          '#weight' => 2000,
          '#value' => t('Cancel'),
          '#validate' => array(
            'content_lock_cancel_submit',
          ),
        );
        if (isset($form['actions']['delete'])) {
          $form['actions']['delete']['#weight'] = 2001;
        }
      }
    }
  }
}