You are here

function save_edit_form_alter in Save & Edit 6

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

Implementation of hook_form_alter().

File

./save_edit.module, line 138

Code

function save_edit_form_alter(&$form, $form_state, $form_id) {
  $node_types = variable_get('save_edit_node_types', array());
  $form_type = $form['type']['#value'];
  if ($form['#id'] == 'node-form' && $node_types[$form_type] && user_access('use save and edit')) {

    //add save and edit btn
    $form['buttons']['save_edit'] = array(
      '#type' => 'submit',
      '#access' => user_access('use save and edit'),
      '#value' => t(check_plain(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) {
      $form['buttons']['save_edit_publish'] = array(
        '#type' => 'submit',
        '#access' => user_access('use save and edit'),
        '#value' => t(check_plain(variable_get('save_edit_publish_button_value', 'Save and Publish'))),
        '#weight' => variable_get('save_edit_publish_button_weight', 7),
        '#submit' => array(
          'redirect_save_edit_submit',
        ),
      );
    }

    // this allows us to modify the default Save button to something we like more
    $form['buttons']['submit'] = array(
      '#type' => 'submit',
      '#access' => !variable_get('node_preview', 0) || !form_get_errors() && isset($form_state['node_preview']),
      '#value' => t(check_plain(variable_get('save_edit_default_save_button_value', 'Save'))),
      '#weight' => variable_get('save_edit_default_save_button_weight', 5),
      '#submit' => array(
        'node_form_submit',
      ),
    );

    // declare default handler & then the custom one
    // for some reason without the default drupal node handler, it is
    // completely ignoring the default/external submit handlers.
    // @todo read up on D6 submit handlers and how to simply append this
    // handler to any handler(s) being called to the normal submit function
    $form['buttons']['save_edit']['#submit'] = array(
      'redirect_save_edit_submit',
    );
  }
}