You are here

function save_edit_form_alter in Save & Edit 7

Same name and namespace in other branches
  1. 8 save_edit.module \save_edit_form_alter()
  2. 6 save_edit.module \save_edit_form_alter()

Implements hook_form_alter().

File

./save_edit.module, line 71
Save & Edit (http://drupal.org/project/save_edit) Provides a button that gives users the option to Save a form they are working on, AND return to the editing form in one step.

Code

function save_edit_form_alter(&$form, $form_state, $form_id) {
  $node_types = variable_get('save_edit_node_types', array());

  // if the type is not set, it's not a node and we are not interested
  if (!isset($form['type']['#value'])) {
    return;
  }
  $form_type = $form['type']['#value'];
  if (strstr($form_id, '_node_form') && !empty($node_types[$form_type]) && user_access('use save and edit')) {

    //add save and edit btn
    $form['actions']['save_edit'] = array(
      '#type' => 'submit',
      '#access' => user_access('use save and edit'),
      '#value' => t(variable_get('save_edit_button_value', 'Save and Edit')),
      '#weight' => variable_get('save_edit_button_weight', 4),
      '#submit' => array(
        'redirect_save_edit_submit',
      ),
    );

    // now if we have chosen to use the auto-unpublish feature, we should
    // create a Publish button to add a clear workflow
    if ((variable_get('save_edit_unpublish', 0) || variable_get('save_edit_unpublish_new_only', 0)) && !$form['#node']->status && !variable_get('save_edit_hide_publish', 0)) {
      $form['actions']['save_edit_publish'] = array(
        '#type' => 'submit',
        '#access' => user_access('use save and edit'),
        '#value' => t(variable_get('save_edit_publish_button_value', 'Save & Publish')),
        '#weight' => variable_get('save_edit_publish_button_weight', 7),
        '#submit' => array(
          'redirect_save_edit_submit',
        ),
      );
    }
    if (variable_get('save_edit_hide_default_save', 0)) {

      //unset($form['actions']['submit']);
      $form['actions']['submit']['#access'] = FALSE;
    }
    if (variable_get('save_edit_hide_default_preview', 0)) {

      //unset($form['actions']['preview']);
      $form['actions']['preview']['#access'] = FALSE;
    }
    if (variable_get('save_edit_hide_default_delete', 0)) {

      //unset($form['actions']['delete']);
      $form['actions']['delete']['#access'] = FALSE;
    }

    // this allows us to modify the default Save button to something we like more
    $form['actions']['submit']['#value'] = t(variable_get('save_edit_default_save_button_value', 'Save'));
    $form['actions']['submit']['#weight'] = variable_get('save_edit_default_save_button_weight', 5);
  }
}