Redirect to the same node for edit after node creation/edit

498 views Asked by At

Drupal8 takes users to the node detailed page after creation or edit. I would like to modify the behaviour and redirect it to the node editing page.

I researched in Google and found that I should use HOOK_form_alter method in the administration theme to apply the redirect.

I have checked the following StackOverflow answer but no success. How can I redirect a Drupal user after they create new content

//hook_form_alter
function adminimal_theme_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  if ($form_id == 'node_article_edit_form' || $form_id == 'node_article_form' && $form_state->isMethodType('POST')) {

    $form['actions']['submit']['#submit'] = 'seven_redirect_handler';

  }
}

function seven_redirect_handler($form, &$form_state) {
  $response = new TrustedRedirectResponse('/node/1');
  $form_state->setResponse($response);
}

For some reasons, it does not work. Any help will be appreciated.

0

There are 0 answers