Redirect to custom page after the node save or update

How to redirect to custom page after the entity save

1. This will work only for submit action

use Drupal\Core\Form\FormStateInterface;
 
//hook_form_alter

function hook_form_alter(&$form, $form_state, $form_id) {
  $form['actions']['submit']['#submit'][] = 'callback_submit';
}



function callback_submit($form, FormStateInterface $form_state) {
  $form_state->setRedirect('custom.page');
}

2. if you want this to be work for other actions too, That means login as admin and see the node save button, you will have select option "save and publish" , "save and unpublish"



function hook_form_alter(&$form, $form_state, $form_id) {
 foreach (array_keys($form['actions']) as $action) {
      if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
          $form['actions'][$action]['#submit'][] = 'callback_submit';
      }
    }
}


function callback_submit($form, FormStateInterface $form_state) {
  $form_state->setRedirect('custom.page');
}