You are here

function revisioning_form_alter in Revisioning 6.3

Same name and namespace in other branches
  1. 8 revisioning.pages.inc \revisioning_form_alter()
  2. 6.4 revisioning.pages.inc \revisioning_form_alter()
  3. 6 revisioning.module \revisioning_form_alter()
  4. 7 revisioning.pages.inc \revisioning_form_alter()

Implementation of hook_form_alter().

Note: for cases where the FORM_ID is known a priori use revisioning_form_FORM_ID_form_alter(), e.g. revisioning_form_node_type_form_alter()

File

./revisioning.pages.inc, line 14
Rendering and altering of pages and forms used by Revisioning

Code

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

  // Alter the Create/Edit form
  if (isset($form['#id']) && $form['#id'] == 'node-form') {
    $content_type = $form['type']['#value'];

    // Note that $form_id == $content_type_$form['#id']
    $form['options']['#collapsed'] = FALSE;

    // Only add this tick-box if user has the 'administer nodes' permission
    if (user_access('administer nodes')) {
      $form['revision_information']['revision_moderation'] = array(
        '#title' => t('New revision in draft, pending moderation'),
        '#type' => 'checkbox',
        '#default_value' => node_tools_content_is_moderated($content_type),
      );
    }
    else {

      // Don't show tickbox, just set default on form
      $form['revision_moderation'] = array(
        '#type' => 'value',
        '#value' => node_tools_content_is_moderated($content_type),
      );
    }

    // In addition to node_form_submit() append our own handler to the list.
    $form['buttons']['submit']['#submit'][] = '_revisioning_form_submit';

    // Change the meaning of the 'Delete (all revisions)' button when editing
    // a revision to be the deletion of the viewed revision, rather than the
    // node.
    if (isset($form['#node']->nid) && isset($form['#node']->vid)) {
      $nid = $form['#node']->nid;
      $vid = $form['#node']->vid;
      if (isset($form['buttons']['delete']) && user_access('delete revisions') && $vid != node_tools_get_current_node_revision_id($nid)) {
        $form['buttons']['delete']['#value'] = t('Delete this revision');
        $form['buttons']['delete']['#submit'][] = '_revisioning_delete_submit';
      }
    }
  }
}