Skip to content

Instantly share code, notes, and snippets.

@pascalduez
Created February 22, 2012 23:33
Show Gist options
  • Select an option

  • Save pascalduez/1888373 to your computer and use it in GitHub Desktop.

Select an option

Save pascalduez/1888373 to your computer and use it in GitHub Desktop.

Revisions

  1. Pascal Duez created this gist Feb 22, 2012.
    27 changes: 27 additions & 0 deletions modulename.module
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    <?php

    /**
    * Implements hook_form_alter().
    */
    function modulename_form_alter(&$form, &$form_state, $form_id) {
    // You might want to filter by content type.
    if ($form_id == 'ctype_node_form') {
    // Add a cancel button.
    $form['actions']['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
    '#access' => TRUE,
    '#weight' => 15,
    '#submit' => array('modulename_form_cancel', 'node_form_submit_build_node'),
    '#limit_validation_errors' => array(),
    );
    }
    }

    /**
    * Custom cancel button callback.
    */
    function modulename_form_cancel($form, &$form_state) {
    $url = $_GET['destination'] ? $_GET['destination'] : 'choose/your/path';
    drupal_goto($url);
    }