Last active
November 22, 2017 06:27
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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