Skip to main content
Removed reverse submit code.
Source Link
vijay
  • 569
  • 3
  • 15

There is another way this can be achievable by adding your custom callback submit function in hook_form_alter which will execute after insert/update node.

E.g:
Check the following code which is for article.


/**
 * Implement hook_form_alter
 *
 * @param type $form
 * @param type $form_state
 * @param type $form_id
 */
function mymodule_form_alter(&$form, &$form_state, $form_id) {
    // Checking form_id
    if ($form_id == 'article_node_form') {
        // Adding custom callback function.
        $form['actions']['submit']['#submit'][] = '_callback_on_postsave';
        // Reverse submit array so newly added submit function should execute at last.
        $form['actions']['submit']['#submit'] = array_reverse($form['actions']['submit']['#submit']);
    }
}

Now you can do your post save functionality in _callback_on_postsave function. E.g:


/**
 * General Callback for form_alter
 * 
 * @param type $form
 * @param type $form_state
 */
function _callback_on_postsave($form, &$form_state) {
    $nid = $form_state['values']['nid'];
    $node = node_load($nid);
    // Do your stuff here 
}

There is another way this can be achievable by adding your custom callback submit function in hook_form_alter which will execute after insert/update node.

E.g:
Check the following code which is for article.


/**
 * Implement hook_form_alter
 *
 * @param type $form
 * @param type $form_state
 * @param type $form_id
 */
function mymodule_form_alter(&$form, &$form_state, $form_id) {
    // Checking form_id
    if ($form_id == 'article_node_form') {
        // Adding custom callback function.
        $form['actions']['submit']['#submit'][] = '_callback_on_postsave';
        // Reverse submit array so newly added submit function should execute at last.
        $form['actions']['submit']['#submit'] = array_reverse($form['actions']['submit']['#submit']);
    }
}

Now you can do your post save functionality in _callback_on_postsave function. E.g:


/**
 * General Callback for form_alter
 * 
 * @param type $form
 * @param type $form_state
 */
function _callback_on_postsave($form, &$form_state) {
    $nid = $form_state['values']['nid'];
    $node = node_load($nid);
    // Do your stuff here 
}

There is another way this can be achievable by adding your custom callback submit function in hook_form_alter which will execute after insert/update node.

E.g:
Check the following code which is for article.


/**
 * Implement hook_form_alter
 *
 * @param type $form
 * @param type $form_state
 * @param type $form_id
 */
function mymodule_form_alter(&$form, &$form_state, $form_id) {
    // Checking form_id
    if ($form_id == 'article_node_form') {
        // Adding custom callback function.
        $form['actions']['submit']['#submit'][] = '_callback_on_postsave';
    }
}

Now you can do your post save functionality in _callback_on_postsave function. E.g:


/**
 * General Callback for form_alter
 * 
 * @param type $form
 * @param type $form_state
 */
function _callback_on_postsave($form, &$form_state) {
    $nid = $form_state['values']['nid'];
    $node = node_load($nid);
    // Do your stuff here 
}

Source Link
vijay
  • 569
  • 3
  • 15

There is another way this can be achievable by adding your custom callback submit function in hook_form_alter which will execute after insert/update node.

E.g:
Check the following code which is for article.


/**
 * Implement hook_form_alter
 *
 * @param type $form
 * @param type $form_state
 * @param type $form_id
 */
function mymodule_form_alter(&$form, &$form_state, $form_id) {
    // Checking form_id
    if ($form_id == 'article_node_form') {
        // Adding custom callback function.
        $form['actions']['submit']['#submit'][] = '_callback_on_postsave';
        // Reverse submit array so newly added submit function should execute at last.
        $form['actions']['submit']['#submit'] = array_reverse($form['actions']['submit']['#submit']);
    }
}

Now you can do your post save functionality in _callback_on_postsave function. E.g:


/**
 * General Callback for form_alter
 * 
 * @param type $form
 * @param type $form_state
 */
function _callback_on_postsave($form, &$form_state) {
    $nid = $form_state['values']['nid'];
    $node = node_load($nid);
    // Do your stuff here 
}