Skip to content

Instantly share code, notes, and snippets.

@devudit
Last active November 22, 2017 06:27
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 devudit/55b50b7e8dce20f671869b46699340a0 to your computer and use it in GitHub Desktop.
Save devudit/55b50b7e8dce20f671869b46699340a0 to your computer and use it in GitHub Desktop.
Redirect back to node edit page after node submit and not on preview
<?php
/**
* Implements hook hook_form_node_form_alter
**/
function hook_form_node_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
foreach (array_keys($form['actions']) as $action) {
if(is_array($form['actions'][$action])) {
$form['actions'][$action]['#submit'][] = 'fwsredirect_remove_destination';
}
}
}
function hook_remove_destination(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
$userInput = $form_state->getUserInput();
if($userInput['op'] != 'Preview') {
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface) {
\Drupal::request()->query->set('destination', 'node/' . $node->id() . '/edit');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment