Skip to content

Instantly share code, notes, and snippets.

@Gonzalo2683
Forked from juampynr/README.md
Last active May 15, 2020 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gonzalo2683/cb820e222eb8035c38357dc75d1ed353 to your computer and use it in GitHub Desktop.
Save Gonzalo2683/cb820e222eb8035c38357dc75d1ed353 to your computer and use it in GitHub Desktop.
[Redirect to node after save] Make Drupal not to redirect to the node display after saving it #Drupal

Drupal's default behavior is to redirect the user to the full display of a node after it has been saved.

If you want to stay in the edit form after saving, add this snippet to a custom module adjusting the module namespace in the two functions.

Acknowledgements

/**
* Implements hook_form_BASE_FORM_ID_alter().
*/
function mymodule_form_node_form_alter(&$form, &$form_state, $form_id) {
$form['actions']['submit']['#submit'][] = '_mymodule_node_submit_redirect';
}
/**
* Extra node form submit handler. Done this way to override the default.
*/
function _mymodule_node_submit_redirect($form, &$form_state) {
if (isset($_GET['destination'])) {
unset($_GET['destination']);
}
$form_state->setRedirect('entity.node.edit_form', ['node' => $form_state->getValue('nid')]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment