You are here

function panelizer_add_revision_info_form in Panelizer 7.2

Same name and namespace in other branches
  1. 7.3 includes/common.inc \panelizer_add_revision_info_form()

Mini form to add revision settings to a panelizer form so that we can properly handle revisioning.

5 calls to panelizer_add_revision_info_form()
panelizer_choose_layout_form in includes/common.inc
panelizer_default_context_form in includes/common.inc
Form to edit contexts that go with a panelizer panel.
panelizer_edit_content_form in includes/common.inc
panelizer_move_content_form in includes/common.inc
panelizer_settings_form in includes/common.inc
Form to configure basic panelizer settings.

File

includes/common.inc, line 115
Contains common forms and routines that different object types use.

Code

function panelizer_add_revision_info_form(&$form, &$form_state) {
  if (empty($form_state['entity'])) {
    return;
  }
  if (empty($form_state['revision info'])) {
    return;
  }
  $entity = $form_state['entity'];
  list($use_revisions, $control_revisions) = $form_state['revision info'];
  if ($use_revisions) {

    // @todo -- what if an entity uses some other flag to control revisioning?
    if (!isset($entity->revision)) {
      $entity->revision = $use_revisions;
      $entity->log = '';
    }
    $form_state['use revisions'] = TRUE;
    $form['revision_information'] = array(
      '#weight' => 11,
    );
    $form['revision_information']['revision'] = array(
      '#type' => 'checkbox',
      '#title' => t('Create new revision'),
      '#default_value' => !empty($entity->revision),
      '#id' => 'edit-revision',
      '#access' => $control_revisions,
    );
    if ($control_revisions || $entity->revision) {
      $form['revision_information']['log'] = array(
        '#type' => 'textarea',
        '#title' => t('Log message'),
        '#description' => t('Provide an explanation of the changes you are making. This will help other authors understand your motivations.'),
        '#default_value' => $entity->log,
      );
      if ($control_revisions) {
        $form['revision_information']['log']['#dependency'] = array(
          'edit-revision' => array(
            1,
          ),
        );
      }
    }

    // Don't override the existing submit, eh?
    if (!empty($form_state['input']['form_id']) && empty($form['#submit']) && function_exists($form_state['input']['form_id'] . '_submit')) {
      $form['#submit'][] = $form_state['input']['form_id'] . '_submit';
    }

    // The submit handler needs to go in a different location depending on
    // what form this is.
    $submit_handler = 'panelizer_add_revision_info_form_submit';
    if (!empty($form['buttons']['submit']['#submit'])) {
      $form['buttons']['submit']['#submit'][] = $submit_handler;
    }
    elseif (!empty($form['buttons']['return']['#submit'])) {
      $form['buttons']['return']['#submit'][] = $submit_handler;
    }
    else {
      $form['#submit'][] = $submit_handler;
    }
  }
}